QCamera3HWI.cpp revision e6ab32d89cf169705236988f0f74309f914c88b7
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 <ui/Fence.h>
39#include <gralloc_priv.h>
40#include "QCamera3HWI.h"
41#include "QCamera3Mem.h"
42#include "QCamera3Channel.h"
43
44using namespace android;
45
46//using namespace android;
47namespace qcamera {
48#define DATA_PTR(MEM_OBJ,INDEX) MEM_OBJ->getPtr( INDEX )
49cam_capability_t *gCamCapability[MM_CAMERA_MAX_NUM_SENSORS];
50parm_buffer_t *prevSettings;
51const camera_metadata_t *gStaticMetadata;
52
53
54camera3_device_ops_t QCamera3HardwareInterface::mCameraOps = {
55    initialize:                         QCamera3HardwareInterface::initialize,
56    configure_streams:                  QCamera3HardwareInterface::configure_streams,
57    register_stream_buffers:            QCamera3HardwareInterface::register_stream_buffers,
58    construct_default_request_settings: QCamera3HardwareInterface::construct_default_request_settings,
59    process_capture_request:            QCamera3HardwareInterface::process_capture_request,
60    get_metadata_vendor_tag_ops:        QCamera3HardwareInterface::get_metadata_vendor_tag_ops,
61    dump:                               QCamera3HardwareInterface::dump,
62};
63
64
65/*===========================================================================
66 * FUNCTION   : QCamera3HardwareInterface
67 *
68 * DESCRIPTION: constructor of QCamera3HardwareInterface
69 *
70 * PARAMETERS :
71 *   @cameraId  : camera ID
72 *
73 * RETURN     : none
74 *==========================================================================*/
75QCamera3HardwareInterface::QCamera3HardwareInterface(int cameraId)
76    : mCameraId(cameraId),
77      mCameraHandle(NULL),
78      mCameraOpened(false),
79      mCallbackOps(NULL)
80{
81    mCameraDevice.common.tag = HARDWARE_DEVICE_TAG;
82    mCameraDevice.common.version = CAMERA_DEVICE_API_VERSION_3_0;
83    mCameraDevice.common.close = close_camera_device;
84    mCameraDevice.ops = &mCameraOps;
85    mCameraDevice.priv = this;
86    gCamCapability[cameraId]->version = CAM_HAL_V3;
87
88    pthread_mutex_init(&mRequestLock, NULL);
89    pthread_cond_init(&mRequestCond, NULL);
90    mPendingRequest = 0;
91
92    pthread_mutex_init(&mMutex, NULL);
93}
94
95/*===========================================================================
96 * FUNCTION   : ~QCamera3HardwareInterface
97 *
98 * DESCRIPTION: destructor of QCamera2HardwareInterface
99 *
100 * PARAMETERS : none
101 *
102 * RETURN     : none
103 *==========================================================================*/
104QCamera3HardwareInterface::~QCamera3HardwareInterface()
105{
106    closeCamera();
107
108    pthread_mutex_destroy(&mRequestLock);
109    pthread_cond_destroy(&mRequestCond);
110
111    pthread_mutex_destroy(&mMutex);
112}
113
114/*===========================================================================
115 * FUNCTION   : openCamera
116 *
117 * DESCRIPTION: open camera
118 *
119 * PARAMETERS :
120 *   @hw_device  : double ptr for camera device struct
121 *
122 * RETURN     : int32_t type of status
123 *              NO_ERROR  -- success
124 *              none-zero failure code
125 *==========================================================================*/
126int QCamera3HardwareInterface::openCamera(struct hw_device_t **hw_device)
127{
128    //int rc = NO_ERROR;
129    int rc = 0;
130    if (mCameraOpened) {
131        *hw_device = NULL;
132        return PERMISSION_DENIED;
133    }
134
135    rc = openCamera();
136    if (rc == 0)
137        *hw_device = &mCameraDevice.common;
138    else
139        *hw_device = NULL;
140    return rc;
141}
142
143/*===========================================================================
144 * FUNCTION   : openCamera
145 *
146 * DESCRIPTION: open camera
147 *
148 * PARAMETERS : none
149 *
150 * RETURN     : int32_t type of status
151 *              NO_ERROR  -- success
152 *              none-zero failure code
153 *==========================================================================*/
154int QCamera3HardwareInterface::openCamera()
155{
156    if (mCameraHandle) {
157        ALOGE("Failure: Camera already opened");
158        return ALREADY_EXISTS;
159    }
160    mCameraHandle = camera_open(mCameraId);
161    if (!mCameraHandle) {
162        ALOGE("camera_open failed.");
163        return UNKNOWN_ERROR;
164    }
165
166    mCameraOpened = true;
167
168    return NO_ERROR;
169}
170
171/*===========================================================================
172 * FUNCTION   : closeCamera
173 *
174 * DESCRIPTION: close camera
175 *
176 * PARAMETERS : none
177 *
178 * RETURN     : int32_t type of status
179 *              NO_ERROR  -- success
180 *              none-zero failure code
181 *==========================================================================*/
182int QCamera3HardwareInterface::closeCamera()
183{
184    int rc = NO_ERROR;
185
186    rc = mCameraHandle->ops->close_camera(mCameraHandle->camera_handle);
187    mCameraHandle = NULL;
188    mCameraOpened = false;
189
190    return rc;
191}
192
193/*===========================================================================
194 * FUNCTION   : sendCaptureResult
195 *
196 * DESCRIPTION: send completed capture result metadata buffer along with possibly
197 *              completed output stream buffers to the framework
198 *
199 * PARAMETERS :
200 *
201 * RETURN     :
202 *==========================================================================*/
203void QCamera3HardwareInterface::sendCaptureResult(const struct camera3_callback_ops *,
204                                                 const camera3_capture_result_t *result)
205{
206    //TODO - Implement
207}
208
209/*===========================================================================
210 * FUNCTION   : notify
211 *
212 * DESCRIPTION: Asynchronous notification callback to framework
213 *
214 * PARAMETERS :
215 *
216 * RETURN     :
217 *
218 *
219 *==========================================================================*/
220
221void QCamera3HardwareInterface::notify(const struct camera3_callback_ops *,
222                                       const camera3_notify_msg_t *msg)
223{
224    //TODO - Implement
225}
226
227
228/*===========================================================================
229 * FUNCTION   : initialize
230 *
231 * DESCRIPTION: Initialize frameworks callback functions
232 *
233 * PARAMETERS :
234 *   @callback_ops : callback function to frameworks
235 *
236 * RETURN     :
237 *
238 *==========================================================================*/
239int QCamera3HardwareInterface::initialize(
240        const struct camera3_callback_ops *callback_ops)
241{
242    int rc;
243
244    pthread_mutex_lock(&mMutex);
245
246    //Create metadata channel and initialize it
247    mMetadataChannel = new QCamera3MetadataChannel(mCameraHandle->camera_handle,
248                    mCameraHandle->ops, captureResultCb,
249                    &gCamCapability[mCameraId]->padding_info, this);
250    if (mMetadataChannel == NULL) {
251        ALOGE("%s: failed to allocate metadata channel", __func__);
252        rc = -ENOMEM;
253        goto err1;
254    }
255    rc = mMetadataChannel->initialize();
256    if (rc < 0) {
257        ALOGE("%s: metadata channel initialization failed", __func__);
258        goto err2;
259    }
260
261    /* Initialize parameter heap and structure */
262    mParamHeap = new QCamera3HeapMemory();
263    if (mParamHeap == NULL) {
264        ALOGE("%s: creation of mParamHeap failed", __func__);
265        goto err2;
266    }
267    rc = mParamHeap->allocate(1, sizeof(parm_buffer_t), false);
268    if (rc < 0) {
269        ALOGE("%s: allocation of mParamHeap failed", __func__);
270        goto err3;
271    }
272    rc = mCameraHandle->ops->map_buf(mCameraHandle->camera_handle,
273                CAM_MAPPING_BUF_TYPE_PARM_BUF,
274                mParamHeap->getFd(0), sizeof(parm_buffer_t));
275    if (rc < 0) {
276        ALOGE("%s: map_buf failed for mParamHeap", __func__);
277        goto err4;
278    }
279    mParameters = (parm_buffer_t *)DATA_PTR(mParamHeap, 0);
280
281    mCallbackOps = callback_ops;
282
283    pthread_mutex_unlock(&mMutex);
284    return 0;
285
286err4:
287    mParamHeap->deallocate();
288err3:
289    delete mParamHeap;
290    mParamHeap = NULL;
291err2:
292    delete mMetadataChannel;
293    mMetadataChannel = NULL;
294err1:
295    pthread_mutex_unlock(&mMutex);
296    return rc;
297}
298
299/*===========================================================================
300 * FUNCTION   : configureStreams
301 *
302 * DESCRIPTION: Reset HAL camera device processing pipeline and set up new input
303 *              and output streams.
304 *
305 * PARAMETERS :
306 *   @stream_list : streams to be configured
307 *
308 * RETURN     :
309 *
310 *==========================================================================*/
311int QCamera3HardwareInterface::configureStreams(
312        camera3_stream_configuration_t *streamList)
313{
314    pthread_mutex_lock(&mMutex);
315
316    // Sanity check stream_list
317    if (streamList == NULL) {
318        ALOGE("%s: NULL stream configuration", __func__);
319        pthread_mutex_unlock(&mMutex);
320        return BAD_VALUE;
321    }
322
323    if (streamList->streams == NULL) {
324        ALOGE("%s: NULL stream list", __func__);
325        pthread_mutex_unlock(&mMutex);
326        return BAD_VALUE;
327    }
328
329    if (streamList->num_streams < 1) {
330        ALOGE("%s: Bad number of streams requested: %d", __func__,
331                streamList->num_streams);
332        pthread_mutex_unlock(&mMutex);
333        return BAD_VALUE;
334    }
335
336    camera3_stream_t *inputStream = NULL;
337    for (size_t i = 0; i < streamList->num_streams; i++) {
338        camera3_stream_t *newStream = streamList->streams[i];
339        if (newStream->stream_type == CAMERA3_STREAM_INPUT) {
340            if (inputStream != NULL) {
341                ALOGE("%s: Multiple input streams requested!", __func__);
342                pthread_mutex_unlock(&mMutex);
343                return BAD_VALUE;
344            }
345            inputStream = newStream;
346        }
347    }
348    mInputStream = inputStream;
349
350    /* TODO: Clean up no longer used streams, and maintain others if this
351     * is not the 1st time configureStreams is called */
352
353    mMetadataChannel->stop();
354
355    /* Allocate channel objects for the requested streams */
356    for (size_t i = 0; i < streamList->num_streams; i++) {
357        camera3_stream_t *newStream = streamList->streams[i];
358        if (newStream->priv == NULL) {
359            //New stream, construct channel
360
361            switch (newStream->stream_type) {
362            case CAMERA3_STREAM_INPUT:
363                newStream->usage = GRALLOC_USAGE_HW_CAMERA_READ;
364                newStream->max_buffers = QCamera3PicChannel::kMaxBuffers;
365                break;
366            case CAMERA3_STREAM_BIDIRECTIONAL:
367                newStream->usage = GRALLOC_USAGE_HW_CAMERA_READ |
368                    GRALLOC_USAGE_HW_CAMERA_WRITE;
369                newStream->max_buffers = QCamera3RegularChannel::kMaxBuffers;
370                break;
371            case CAMERA3_STREAM_OUTPUT:
372                newStream->usage = GRALLOC_USAGE_HW_CAMERA_WRITE;
373                newStream->max_buffers = QCamera3RegularChannel::kMaxBuffers;
374                break;
375            default:
376                ALOGE("%s: Invalid stream_type %d", __func__, newStream->stream_type);
377                break;
378            }
379
380            if (newStream->stream_type == CAMERA3_STREAM_OUTPUT ||
381                newStream->stream_type == CAMERA3_STREAM_BIDIRECTIONAL) {
382                QCamera3Channel *channel;
383                switch (newStream->format) {
384                case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
385                    channel = new QCamera3RegularChannel(mCameraHandle->camera_handle,
386                            mCameraHandle->ops, captureResultCb,
387                            &gCamCapability[mCameraId]->padding_info, this, newStream);
388                    if (channel == NULL) {
389                        ALOGE("%s: allocation of channel failed", __func__);
390                        pthread_mutex_unlock(&mMutex);
391                        return -ENOMEM;
392                    }
393
394                    newStream->priv = channel;
395                    break;
396                case HAL_PIXEL_FORMAT_BLOB:
397                    channel = new QCamera3PicChannel(mCameraHandle->camera_handle,
398                            mCameraHandle->ops, captureResultCb,
399                            &gCamCapability[mCameraId]->padding_info, this, newStream);
400                    if (channel == NULL) {
401                        ALOGE("%s: allocation of channel failed", __func__);
402                        pthread_mutex_unlock(&mMutex);
403                        return -ENOMEM;
404                    }
405
406                    newStream->priv = channel;
407                    break;
408
409                //TODO: Add support for app consumed format?
410                default:
411                    ALOGE("%s: not a supported format 0x%x", __func__, newStream->format);
412                    break;
413                }
414            }
415        } else {
416            // Channel already exists for this stream
417            // Do nothing for now
418        }
419    }
420
421    // Cannot reuse settings across configure call
422    memset(mParameters, 0, sizeof(parm_buffer_t));
423    pthread_mutex_unlock(&mMutex);
424    return 0;
425}
426
427/*===========================================================================
428 * FUNCTION   : validateCaptureRequest
429 *
430 * DESCRIPTION: validate a capture request from camera service
431 *
432 * PARAMETERS :
433 *   @request : request from framework to process
434 *
435 * RETURN     :
436 *
437 *==========================================================================*/
438int QCamera3HardwareInterface::validateCaptureRequest(
439                    camera3_capture_request_t *request)
440{
441    int rc = NO_ERROR;
442    ssize_t idx = 0;
443    const camera3_stream_buffer_t *b;
444    CameraMetadata meta;
445
446    /* Sanity check the request */
447    if (request == NULL) {
448        ALOGE("%s: NULL capture request", __func__);
449        return BAD_VALUE;
450    }
451
452    uint32_t frameNumber = request->frame_number;
453    if (request->input_buffer != NULL &&
454            request->input_buffer->stream != mInputStream) {
455        ALOGE("%s: Request %d: Input buffer not from input stream!",
456                __FUNCTION__, frameNumber);
457        return BAD_VALUE;
458    }
459    if (request->num_output_buffers < 1 || request->output_buffers == NULL) {
460        ALOGE("%s: Request %d: No output buffers provided!",
461                __FUNCTION__, frameNumber);
462        return BAD_VALUE;
463    }
464    if (request->input_buffer != NULL) {
465        //TODO
466        ALOGE("%s: Not supporting input buffer yet", __func__);
467        return BAD_VALUE;
468    }
469
470    // Validate all buffers
471    b = request->output_buffers;
472    do {
473        QCamera3Channel *channel =
474                static_cast<QCamera3Channel*>(b->stream->priv);
475        if (channel == NULL) {
476            ALOGE("%s: Request %d: Buffer %d: Unconfigured stream!",
477                    __func__, frameNumber, idx);
478            return BAD_VALUE;
479        }
480        if (b->status != CAMERA3_BUFFER_STATUS_OK) {
481            ALOGE("%s: Request %d: Buffer %d: Status not OK!",
482                    __func__, frameNumber, idx);
483            return BAD_VALUE;
484        }
485        if (b->release_fence != -1) {
486            ALOGE("%s: Request %d: Buffer %d: Has a release fence!",
487                    __func__, frameNumber, idx);
488            return BAD_VALUE;
489        }
490        if (b->buffer == NULL) {
491            ALOGE("%s: Request %d: Buffer %d: NULL buffer handle!",
492                    __func__, frameNumber, idx);
493            return BAD_VALUE;
494        }
495        idx++;
496        b = request->output_buffers + idx;
497    } while (idx < (ssize_t)request->num_output_buffers);
498
499    return NO_ERROR;
500}
501
502/*===========================================================================
503 * FUNCTION   : registerStreamBuffers
504 *
505 * DESCRIPTION: Register buffers for a given stream with the HAL device.
506 *
507 * PARAMETERS :
508 *   @stream_list : streams to be configured
509 *
510 * RETURN     :
511 *
512 *==========================================================================*/
513int QCamera3HardwareInterface::registerStreamBuffers(
514        const camera3_stream_buffer_set_t *buffer_set)
515{
516    int rc = 0;
517
518    pthread_mutex_lock(&mMutex);
519
520    if (buffer_set == NULL) {
521        ALOGE("%s: Invalid buffer_set parameter.", __func__);
522        pthread_mutex_unlock(&mMutex);
523        return -EINVAL;
524    }
525    if (buffer_set->stream == NULL) {
526        ALOGE("%s: Invalid stream parameter.", __func__);
527        pthread_mutex_unlock(&mMutex);
528        return -EINVAL;
529    }
530    if (buffer_set->num_buffers < 1) {
531        ALOGE("%s: Invalid num_buffers %d.", __func__, buffer_set->num_buffers);
532        pthread_mutex_unlock(&mMutex);
533        return -EINVAL;
534    }
535    if (buffer_set->buffers == NULL) {
536        ALOGE("%s: Invalid buffers parameter.", __func__);
537        pthread_mutex_unlock(&mMutex);
538        return -EINVAL;
539    }
540
541    camera3_stream_t *stream = buffer_set->stream;
542    QCamera3Channel *channel = (QCamera3Channel *)stream->priv;
543
544    if (stream->stream_type != CAMERA3_STREAM_OUTPUT) {
545        ALOGE("%s: not yet support non output type stream", __func__);
546        pthread_mutex_unlock(&mMutex);
547        return -EINVAL;
548    }
549    rc = channel->registerBuffers(buffer_set->num_buffers, buffer_set->buffers);
550    if (rc < 0) {
551        ALOGE("%s: registerBUffers for stream %p failed", __func__, stream);
552        pthread_mutex_unlock(&mMutex);
553        return -ENODEV;
554    }
555
556    pthread_mutex_unlock(&mMutex);
557    return NO_ERROR;
558}
559
560/*===========================================================================
561 * FUNCTION   : processCaptureRequest
562 *
563 * DESCRIPTION: process a capture request from camera service
564 *
565 * PARAMETERS :
566 *   @request : request from framework to process
567 *
568 * RETURN     :
569 *
570 *==========================================================================*/
571int QCamera3HardwareInterface::processCaptureRequest(
572                    camera3_capture_request_t *request)
573{
574    int rc = NO_ERROR;
575    ssize_t idx = 0;
576    const camera3_stream_buffer_t *b;
577    CameraMetadata meta;
578
579    pthread_mutex_lock(&mMutex);
580
581    rc = validateCaptureRequest(request);
582    if (rc != NO_ERROR) {
583        ALOGE("%s: incoming request is not valid", __func__);
584        pthread_mutex_unlock(&mMutex);
585        return rc;
586    }
587
588    uint32_t frameNumber = request->frame_number;
589
590    rc = setFrameParameters(request->settings);
591    if (rc < 0) {
592        ALOGE("%s: fail to set frame parameters", __func__);
593        pthread_mutex_unlock(&mMutex);
594        return rc;
595    }
596
597    // Acquire all request buffers first
598    for (size_t i = 0; i < request->num_output_buffers; i++) {
599        const camera3_stream_buffer_t& output = request->output_buffers[i];
600        sp<Fence> acquireFence = new Fence(output.acquire_fence);
601        rc = acquireFence->wait(Fence::TIMEOUT_NEVER);
602        if (rc != OK) {
603            ALOGE("%s: fence wait failed %d", __func__, rc);
604            pthread_mutex_unlock(&mMutex);
605            return rc;
606        }
607    }
608
609    // Notify metadata channel we receive a request
610    mMetadataChannel->request(NULL, frameNumber);
611
612    // Call request on other streams
613    for (size_t i = 0; i < request->num_output_buffers; i++) {
614        const camera3_stream_buffer_t& output = request->output_buffers[i];
615        QCamera3Channel *channel = (QCamera3Channel *)output.stream->priv;
616        if (channel == NULL) {
617            ALOGE("%s: invalid channel pointer for stream", __func__);
618            continue;
619        }
620
621        rc = channel->request(output.buffer, frameNumber);
622        if (rc < 0)
623            ALOGE("%s: request failed", __func__);
624    }
625
626    //Block on conditional variable
627    pthread_mutex_lock(&mRequestLock);
628    mPendingRequest = 1;
629    while (mPendingRequest == 1) {
630        pthread_cond_wait(&mRequestCond, &mRequestLock);
631    }
632    pthread_mutex_unlock(&mRequestLock);
633
634    pthread_mutex_unlock(&mMutex);
635    return rc;
636}
637
638/*===========================================================================
639 * FUNCTION   : getMetadataVendorTagOps
640 *
641 * DESCRIPTION:
642 *
643 * PARAMETERS :
644 *
645 *
646 * RETURN     :
647 *==========================================================================*/
648void QCamera3HardwareInterface::getMetadataVendorTagOps(vendor_tag_query_ops_t* ops)
649{
650    /* Enable locks when we eventually add Vendor Tags */
651    /*
652    pthread_mutex_lock(&mMutex);
653
654    pthread_mutex_unlock(&mMutex);
655    */
656    return;
657}
658
659/*===========================================================================
660 * FUNCTION   : dump
661 *
662 * DESCRIPTION:
663 *
664 * PARAMETERS :
665 *
666 *
667 * RETURN     :
668 *==========================================================================*/
669void QCamera3HardwareInterface::dump(int fd)
670{
671    /*Enable lock when we implement this function*/
672    /*
673    pthread_mutex_lock(&mMutex);
674
675    pthread_mutex_unlock(&mMutex);
676    */
677    return;
678}
679
680/*===========================================================================
681 * FUNCTION   : captureResultCb
682 *
683 * DESCRIPTION: Callback handler for all capture result (streams, as well as metadata)
684 *
685 * PARAMETERS :
686 *   @metadata : metadata information
687 *   @buffer   : actual gralloc buffer to be returned to frameworks. NULL if metadata.
688 *
689 * RETURN     : NONE
690 *==========================================================================*/
691void QCamera3HardwareInterface::captureResultCb(metadata_buffer_t *metadata,
692                camera3_stream_buffer_t *buffer, uint32_t frame_number)
693{
694    pthread_mutex_lock(&mCaptureResultLock);
695    camera3_capture_result_t result;
696
697
698    if (metadata) {
699        // Signal to unblock processCaptureRequest
700        pthread_mutex_lock(&mRequestLock);
701        mPendingRequest = 0;
702        pthread_cond_signal(&mRequestCond);
703        pthread_mutex_unlock(&mRequestLock);
704
705        //TODO: Add translation from metadata_buffer_t to CameraMetadata
706        // for now, hardcode timestamp only.
707        CameraMetadata camMetadata;
708        uint32_t *frame_number = (uint32_t *)POINTER_OF(CAM_INTF_META_FRAME_NUMBER, metadata);
709        nsecs_t captureTime = 1000000 * (*frame_number) * 33;
710        camMetadata.update(ANDROID_SENSOR_TIMESTAMP, &captureTime, 1);
711
712        result.result = camMetadata.release();
713        if (!result.result) {
714            result.frame_number = *frame_number;
715            result.num_output_buffers = 0;
716            result.output_buffers = NULL;
717            mCallbackOps->process_capture_result(mCallbackOps, &result);
718
719            free_camera_metadata((camera_metadata_t*)result.result);
720        }
721    } else {
722        result.result = NULL;
723        result.frame_number = frame_number;
724        result.num_output_buffers = 1;
725        result.output_buffers = buffer;
726        mCallbackOps->process_capture_result(mCallbackOps, &result);
727    }
728
729    pthread_mutex_unlock(&mCaptureResultLock);
730    return;
731}
732
733#define DATA_PTR(MEM_OBJ,INDEX) MEM_OBJ->getPtr( INDEX )
734/*===========================================================================
735 * FUNCTION   : initCapabilities
736 *
737 * DESCRIPTION: initialize camera capabilities in static data struct
738 *
739 * PARAMETERS :
740 *   @cameraId  : camera Id
741 *
742 * RETURN     : int32_t type of status
743 *              NO_ERROR  -- success
744 *              none-zero failure code
745 *==========================================================================*/
746int QCamera3HardwareInterface::initCapabilities(int cameraId)
747{
748    int rc = 0;
749    mm_camera_vtbl_t *cameraHandle = NULL;
750    QCamera3HeapMemory *capabilityHeap = NULL;
751
752    cameraHandle = camera_open(cameraId);
753    if (!cameraHandle) {
754        ALOGE("%s: camera_open failed", __func__);
755        rc = -1;
756        goto open_failed;
757    }
758
759    capabilityHeap = new QCamera3HeapMemory();
760    if (capabilityHeap == NULL) {
761        ALOGE("%s: creation of capabilityHeap failed", __func__);
762        goto heap_creation_failed;
763    }
764    /* Allocate memory for capability buffer */
765    rc = capabilityHeap->allocate(1, sizeof(cam_capability_t), false);
766    if(rc != OK) {
767        ALOGE("%s: No memory for cappability", __func__);
768        goto allocate_failed;
769    }
770
771    /* Map memory for capability buffer */
772    memset(DATA_PTR(capabilityHeap,0), 0, sizeof(cam_capability_t));
773    rc = cameraHandle->ops->map_buf(cameraHandle->camera_handle,
774                                CAM_MAPPING_BUF_TYPE_CAPABILITY,
775                                capabilityHeap->getFd(0),
776                                sizeof(cam_capability_t));
777    if(rc < 0) {
778        ALOGE("%s: failed to map capability buffer", __func__);
779        goto map_failed;
780    }
781
782    /* Query Capability */
783    rc = cameraHandle->ops->query_capability(cameraHandle->camera_handle);
784    if(rc < 0) {
785        ALOGE("%s: failed to query capability",__func__);
786        goto query_failed;
787    }
788    gCamCapability[cameraId] = (cam_capability_t *)malloc(sizeof(cam_capability_t));
789    if (!gCamCapability[cameraId]) {
790        ALOGE("%s: out of memory", __func__);
791        goto query_failed;
792    }
793    memcpy(gCamCapability[cameraId], DATA_PTR(capabilityHeap,0),
794                                        sizeof(cam_capability_t));
795    rc = 0;
796
797query_failed:
798    cameraHandle->ops->unmap_buf(cameraHandle->camera_handle,
799                            CAM_MAPPING_BUF_TYPE_CAPABILITY);
800map_failed:
801    capabilityHeap->deallocate();
802allocate_failed:
803    delete capabilityHeap;
804heap_creation_failed:
805    cameraHandle->ops->close_camera(cameraHandle->camera_handle);
806    cameraHandle = NULL;
807open_failed:
808    return rc;
809}
810
811/*===========================================================================
812 * FUNCTION   : initStaticMetadata
813 *
814 * DESCRIPTION: initialize the static metadata
815 *
816 * PARAMETERS :
817 *   @cameraId  : camera Id
818 *
819 * RETURN     : int32_t type of status
820 *              0  -- success
821 *              non-zero failure code
822 *==========================================================================*/
823int QCamera3HardwareInterface::initStaticMetadata(int cameraId)
824{
825    int rc = 0;
826    android::CameraMetadata staticInfo;
827
828    staticInfo.update(ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE,
829                    &gCamCapability[cameraId]->min_focus_distance, 1);
830
831    staticInfo.update(ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE,
832                    &gCamCapability[cameraId]->hyper_focal_distance, 1);
833
834    staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS,
835                      gCamCapability[cameraId]->focal_lengths,
836                      gCamCapability[cameraId]->focal_lengths_count);
837
838
839    staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_APERTURES,
840                      gCamCapability[cameraId]->apertures,
841                      gCamCapability[cameraId]->apertures_count);
842
843    staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_FILTER_DENSITIES,
844                gCamCapability[cameraId]->filter_densities,
845                gCamCapability[cameraId]->filter_densities_count);
846
847
848    staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION,
849                      (int*)gCamCapability[cameraId]->optical_stab_modes,
850                      gCamCapability[cameraId]->optical_stab_modes_count);
851
852    staticInfo.update(ANDROID_LENS_POSITION,
853                      gCamCapability[cameraId]->lens_position,
854                      sizeof(gCamCapability[cameraId]->lens_position)/ sizeof(float));
855
856    static const int32_t lens_shading_map_size[] = {gCamCapability[cameraId]->lens_shading_map_size.width,
857                                                    gCamCapability[cameraId]->lens_shading_map_size.height};
858    staticInfo.update(ANDROID_LENS_INFO_SHADING_MAP_SIZE,
859                      lens_shading_map_size,
860                      sizeof(lens_shading_map_size)/sizeof(int32_t));
861
862    staticInfo.update(ANDROID_LENS_INFO_SHADING_MAP, gCamCapability[cameraId]->lens_shading_map,
863            sizeof(gCamCapability[cameraId]->lens_shading_map_size)/ sizeof(cam_dimension_t));
864
865    static const int32_t geo_correction_map_size[] = {gCamCapability[cameraId]->geo_correction_map_size.width,
866                                                            gCamCapability[cameraId]->geo_correction_map_size.height};
867    staticInfo.update(ANDROID_LENS_INFO_GEOMETRIC_CORRECTION_MAP_SIZE,
868            geo_correction_map_size,
869            sizeof(geo_correction_map_size)/sizeof(int32_t));
870
871    staticInfo.update(ANDROID_LENS_INFO_GEOMETRIC_CORRECTION_MAP,
872                       gCamCapability[cameraId]->geo_correction_map,
873            sizeof(gCamCapability[cameraId]->geo_correction_map_size)/ sizeof(cam_dimension_t));
874
875    staticInfo.update(ANDROID_SENSOR_INFO_PHYSICAL_SIZE,
876            gCamCapability[cameraId]->sensor_physical_size, 2);
877
878    staticInfo.update(ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE,
879            gCamCapability[cameraId]->exposure_time_range, 2);
880
881    staticInfo.update(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION,
882            &gCamCapability[cameraId]->max_frame_duration, 1);
883
884
885    staticInfo.update(ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT,
886                     (int*)&gCamCapability[cameraId]->color_arrangement, 1);
887
888    static const int32_t pixel_array_size[] = {gCamCapability[cameraId]->pixel_array_size.width,
889                                               gCamCapability[cameraId]->pixel_array_size.height};
890    staticInfo.update(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE,
891                      pixel_array_size, 2);
892
893    static const int32_t active_array_size[] = {gCamCapability[cameraId]->active_array_size.width,
894                                                gCamCapability[cameraId]->active_array_size.height};
895    staticInfo.update(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE,
896                      active_array_size, 2);
897
898    staticInfo.update(ANDROID_SENSOR_INFO_WHITE_LEVEL,
899            &gCamCapability[cameraId]->white_level, 1);
900
901    staticInfo.update(ANDROID_SENSOR_BLACK_LEVEL_PATTERN,
902            gCamCapability[cameraId]->black_level_pattern, 4);
903
904    staticInfo.update(ANDROID_FLASH_INFO_CHARGE_DURATION,
905                      &gCamCapability[cameraId]->flash_charge_duration, 1);
906
907    staticInfo.update(ANDROID_TONEMAP_MAX_CURVE_POINTS,
908                      &gCamCapability[cameraId]->max_tone_map_curve_points, 1);
909
910    staticInfo.update(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT,
911                      (int*)&gCamCapability[cameraId]->max_face_detection_count, 1);
912
913    staticInfo.update(ANDROID_STATISTICS_INFO_HISTOGRAM_BUCKET_COUNT,
914                      &gCamCapability[cameraId]->histogram_size, 1);
915
916    staticInfo.update(ANDROID_STATISTICS_INFO_MAX_HISTOGRAM_COUNT,
917            &gCamCapability[cameraId]->max_histogram_count, 1);
918
919    static const int32_t sharpness_map_size[] = {gCamCapability[cameraId]->sharpness_map_size.width,
920                                                gCamCapability[cameraId]->sharpness_map_size.height};
921
922    staticInfo.update(ANDROID_STATISTICS_INFO_SHARPNESS_MAP_SIZE,
923            sharpness_map_size, sizeof(sharpness_map_size)/sizeof(int32_t));
924
925    staticInfo.update(ANDROID_STATISTICS_INFO_MAX_SHARPNESS_MAP_VALUE,
926            &gCamCapability[cameraId]->max_sharpness_map_value, 1);
927
928
929    staticInfo.update(ANDROID_SCALER_AVAILABLE_RAW_MIN_DURATIONS,
930                      &gCamCapability[cameraId]->raw_min_duration,
931                       1);
932
933    static const int32_t exposureCompensationRange[] = {gCamCapability[cameraId]->exposure_compensation_min,
934                                                        gCamCapability[cameraId]->exposure_compensation_max};
935    staticInfo.update(ANDROID_CONTROL_AE_COMPENSATION_RANGE,
936            exposureCompensationRange,
937            sizeof(exposureCompensationRange)/sizeof(int32_t));
938
939    uint8_t lensFacing = (gCamCapability[cameraId]->position == CAM_POSITION_BACK) ?
940            ANDROID_LENS_FACING_BACK : ANDROID_LENS_FACING_FRONT;
941    staticInfo.update(ANDROID_LENS_FACING, &lensFacing, 1);
942
943    gStaticMetadata = staticInfo.release();
944    return rc;
945}
946
947/*===========================================================================
948 * FUNCTION   : getCapabilities
949 *
950 * DESCRIPTION: query camera capabilities
951 *
952 * PARAMETERS :
953 *   @cameraId  : camera Id
954 *   @info      : camera info struct to be filled in with camera capabilities
955 *
956 * RETURN     : int32_t type of status
957 *              NO_ERROR  -- success
958 *              none-zero failure code
959 *==========================================================================*/
960int QCamera3HardwareInterface::getCamInfo(int cameraId,
961                                    struct camera_info *info)
962{
963    int rc = 0;
964
965    if (NULL == gCamCapability[cameraId]) {
966        rc = initCapabilities(cameraId);
967        if (rc < 0) {
968            //pthread_mutex_unlock(&g_camlock);
969            return rc;
970        }
971    }
972
973    if (NULL == gStaticMetadata) {
974        rc = initStaticMetadata(cameraId);
975        if (rc < 0) {
976            return rc;
977        }
978    }
979
980    switch(gCamCapability[cameraId]->position) {
981    case CAM_POSITION_BACK:
982        info->facing = CAMERA_FACING_BACK;
983        break;
984
985    case CAM_POSITION_FRONT:
986        info->facing = CAMERA_FACING_FRONT;
987        break;
988
989    default:
990        ALOGE("%s:Unknown position type for camera id:%d", __func__, cameraId);
991        rc = -1;
992        break;
993    }
994
995
996    info->orientation = gCamCapability[cameraId]->sensor_mount_angle;
997    info->device_version = HARDWARE_DEVICE_API_VERSION(3, 0);
998    info->static_camera_characteristics = gStaticMetadata;
999
1000    return rc;
1001}
1002
1003/*===========================================================================
1004 * FUNCTION   : translateMetadata
1005 *
1006 * DESCRIPTION: translate the metadata into camera_metadata_t
1007 *
1008 * PARAMETERS : type of the request
1009 *
1010 *
1011 * RETURN     : success: camera_metadata_t*
1012 *              failure: NULL
1013 *
1014 *==========================================================================*/
1015camera_metadata_t* QCamera3HardwareInterface::translateMetadata(int type)
1016{
1017    pthread_mutex_lock(&mMutex);
1018
1019    if (mDefaultMetadata[type] != NULL) {
1020        pthread_mutex_unlock(&mMutex);
1021        return mDefaultMetadata[type];
1022    }
1023    //first time we are handling this request
1024    //fill up the metadata structure using the wrapper class
1025    android::CameraMetadata settings;
1026    //translate from cam_capability_t to camera_metadata_tag_t
1027    static const uint8_t requestType = ANDROID_REQUEST_TYPE_CAPTURE;
1028    settings.update(ANDROID_REQUEST_TYPE, &requestType, 1);
1029
1030    /*control*/
1031
1032    uint8_t controlIntent = 0;
1033    switch (type) {
1034      case CAMERA3_TEMPLATE_PREVIEW:
1035        controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW;
1036        break;
1037      case CAMERA3_TEMPLATE_STILL_CAPTURE:
1038        controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE;
1039        break;
1040      case CAMERA3_TEMPLATE_VIDEO_RECORD:
1041        controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD;
1042        break;
1043      case CAMERA3_TEMPLATE_VIDEO_SNAPSHOT:
1044        controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT;
1045        break;
1046      case CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG:
1047        controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG;
1048        break;
1049      default:
1050        controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_CUSTOM;
1051        break;
1052    }
1053    settings.update(ANDROID_CONTROL_CAPTURE_INTENT, &controlIntent, 1);
1054
1055    settings.update(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION,
1056            &gCamCapability[mCameraId]->exposure_compensation_default, 1);
1057
1058    static const uint8_t aeLock = ANDROID_CONTROL_AE_LOCK_OFF;
1059    settings.update(ANDROID_CONTROL_AE_LOCK, &aeLock, 1);
1060
1061    static const uint8_t awbLock = ANDROID_CONTROL_AWB_LOCK_OFF;
1062    settings.update(ANDROID_CONTROL_AWB_LOCK, &awbLock, 1);
1063
1064    static const uint8_t awbMode = ANDROID_CONTROL_AWB_MODE_AUTO;
1065    settings.update(ANDROID_CONTROL_AWB_MODE, &awbMode, 1);
1066
1067    static const uint8_t controlMode = ANDROID_CONTROL_MODE_AUTO;
1068    settings.update(ANDROID_CONTROL_MODE, &controlMode, 1);
1069
1070    static const uint8_t effectMode = ANDROID_CONTROL_EFFECT_MODE_OFF;
1071    settings.update(ANDROID_CONTROL_EFFECT_MODE, &effectMode, 1);
1072
1073    static const uint8_t sceneMode = ANDROID_CONTROL_SCENE_MODE_FACE_PRIORITY; //similar to AUTO?
1074    settings.update(ANDROID_CONTROL_SCENE_MODE, &sceneMode, 1);
1075
1076    /*flash*/
1077    static const uint8_t flashMode = ANDROID_FLASH_MODE_OFF;
1078    settings.update(ANDROID_FLASH_MODE, &flashMode, 1);
1079
1080
1081    /* lens */
1082    static const float default_aperture = gCamCapability[mCameraId]->apertures[0];
1083    settings.update(ANDROID_LENS_APERTURE, &default_aperture, 1);
1084
1085    static const float default_filter_density = gCamCapability[mCameraId]->filter_densities[0];
1086    settings.update(ANDROID_LENS_FILTER_DENSITY, &default_filter_density, 1);
1087
1088    static const float default_focal_length = gCamCapability[mCameraId]->focal_lengths[0];
1089    settings.update(ANDROID_LENS_FOCAL_LENGTH, &default_focal_length, 1);
1090
1091    mDefaultMetadata[type] = settings.release();
1092
1093    pthread_mutex_unlock(&mMutex);
1094    return mDefaultMetadata[type];
1095}
1096
1097/*===========================================================================
1098 * FUNCTION   : setFrameParameters
1099 *
1100 * DESCRIPTION: set parameters per frame as requested in the metadata from
1101 *              framework
1102 *
1103 * PARAMETERS :
1104 *   @settings  : frame settings information from framework
1105 *
1106 *
1107 * RETURN     : success: NO_ERROR
1108 *              failure:
1109 *==========================================================================*/
1110int QCamera3HardwareInterface::setFrameParameters(const camera_metadata_t *settings)
1111{
1112    /*translate from camera_metadata_t type to parm_type_t*/
1113    int rc = 0;
1114    android::CameraMetadata frame_settings;
1115    if (settings == NULL && prevSettings == NULL) {
1116        /*settings cannot be null for the first request*/
1117        return BAD_VALUE;
1118    } else if (settings == NULL) {
1119        /*do nothing? we have already configured the settings previously*/
1120    } else{
1121        //reset the prevSettings
1122        if (prevSettings != NULL) {
1123            free(prevSettings);
1124            prevSettings = NULL;
1125        }
1126        rc = translateMetadataToParameters(settings);
1127    }
1128    /*set the parameters to backend*/
1129    return rc;
1130}
1131
1132/*===========================================================================
1133 * FUNCTION   : translateMetadataToParameters
1134 *
1135 * DESCRIPTION: read from the camera_metadata_t and change to parm_type_t
1136 *
1137 *
1138 * PARAMETERS :
1139 *   @settings  : frame settings information from framework
1140 *
1141 *
1142 * RETURN     : success: NO_ERROR
1143 *              failure:
1144 *==========================================================================*/
1145int QCamera3HardwareInterface::translateMetadataToParameters
1146                                  (const camera_metadata_t *settings)
1147{
1148    return 0;
1149}
1150
1151/*===========================================================================
1152 * FUNCTION   : captureResultCb
1153 *
1154 * DESCRIPTION: Callback handler for all channels (streams, as well as metadata)
1155 *
1156 * PARAMETERS :
1157 *   @frame  : frame information from mm-camera-interface
1158 *   @buffer : actual gralloc buffer to be returned to frameworks. NULL if metadata.
1159 *   @userdata: userdata
1160 *
1161 * RETURN     : NONE
1162 *==========================================================================*/
1163void QCamera3HardwareInterface::captureResultCb(metadata_buffer_t *metadata,
1164                camera3_stream_buffer_t *buffer,
1165                uint32_t frame_number, void *userdata)
1166{
1167    QCamera3HardwareInterface *hw = (QCamera3HardwareInterface *)userdata;
1168    if (hw == NULL) {
1169        ALOGE("%s: Invalid hw %p", __func__, hw);
1170        return;
1171    }
1172
1173    hw->captureResultCb(metadata, buffer, frame_number);
1174    return;
1175}
1176
1177/*===========================================================================
1178 * FUNCTION   : initialize
1179 *
1180 * DESCRIPTION: Pass framework callback pointers to HAL
1181 *
1182 * PARAMETERS :
1183 *
1184 *
1185 * RETURN     : Success : 0
1186 *              Failure: -ENODEV
1187 *==========================================================================*/
1188
1189int QCamera3HardwareInterface::initialize(const struct camera3_device *device,
1190                                  const camera3_callback_ops_t *callback_ops)
1191{
1192    QCamera3HardwareInterface *hw =
1193        reinterpret_cast<QCamera3HardwareInterface *>(device->priv);
1194    if (!hw) {
1195        ALOGE("%s: NULL camera device", __func__);
1196        return -ENODEV;
1197    }
1198
1199    return hw->initialize(callback_ops);
1200}
1201
1202/*===========================================================================
1203 * FUNCTION   : configure_streams
1204 *
1205 * DESCRIPTION:
1206 *
1207 * PARAMETERS :
1208 *
1209 *
1210 * RETURN     : Success: 0
1211 *              Failure: -EINVAL (if stream configuration is invalid)
1212 *                       -ENODEV (fatal error)
1213 *==========================================================================*/
1214
1215int QCamera3HardwareInterface::configure_streams(
1216        const struct camera3_device *device,
1217        camera3_stream_configuration_t *stream_list)
1218{
1219    QCamera3HardwareInterface *hw =
1220        reinterpret_cast<QCamera3HardwareInterface *>(device->priv);
1221    if (!hw) {
1222        ALOGE("%s: NULL camera device", __func__);
1223        return -ENODEV;
1224    }
1225    return hw->configureStreams(stream_list);
1226}
1227
1228/*===========================================================================
1229 * FUNCTION   : register_stream_buffers
1230 *
1231 * DESCRIPTION: Register stream buffers with the device
1232 *
1233 * PARAMETERS :
1234 *
1235 * RETURN     :
1236 *==========================================================================*/
1237int QCamera3HardwareInterface::register_stream_buffers(
1238        const struct camera3_device *device,
1239        const camera3_stream_buffer_set_t *buffer_set)
1240{
1241    QCamera3HardwareInterface *hw =
1242        reinterpret_cast<QCamera3HardwareInterface *>(device->priv);
1243    if (!hw) {
1244        ALOGE("%s: NULL camera device", __func__);
1245        return -ENODEV;
1246    }
1247    return hw->registerStreamBuffers(buffer_set);
1248}
1249
1250/*===========================================================================
1251 * FUNCTION   : construct_default_request_settings
1252 *
1253 * DESCRIPTION: Configure a settings buffer to meet the required use case
1254 *
1255 * PARAMETERS :
1256 *
1257 *
1258 * RETURN     : Success: Return valid metadata
1259 *              Failure: Return NULL
1260 *==========================================================================*/
1261const camera_metadata_t* QCamera3HardwareInterface::
1262    construct_default_request_settings(const struct camera3_device *device,
1263                                        int type)
1264{
1265
1266    camera_metadata_t* fwk_metadata = NULL;
1267    QCamera3HardwareInterface *hw =
1268        reinterpret_cast<QCamera3HardwareInterface *>(device->priv);
1269    if (!hw) {
1270        ALOGE("%s: NULL camera device", __func__);
1271        return NULL;
1272    }
1273
1274    fwk_metadata = hw->translateMetadata(type);
1275
1276    return fwk_metadata;
1277}
1278
1279/*===========================================================================
1280 * FUNCTION   : process_capture_request
1281 *
1282 * DESCRIPTION:
1283 *
1284 * PARAMETERS :
1285 *
1286 *
1287 * RETURN     :
1288 *==========================================================================*/
1289int QCamera3HardwareInterface::process_capture_request(
1290                    const struct camera3_device *device,
1291                    camera3_capture_request_t *request)
1292{
1293    QCamera3HardwareInterface *hw =
1294        reinterpret_cast<QCamera3HardwareInterface *>(device->priv);
1295    if (!hw) {
1296        ALOGE("%s: NULL camera device", __func__);
1297        return -EINVAL;
1298    }
1299
1300    return hw->processCaptureRequest(request);
1301}
1302
1303/*===========================================================================
1304 * FUNCTION   : get_metadata_vendor_tag_ops
1305 *
1306 * DESCRIPTION:
1307 *
1308 * PARAMETERS :
1309 *
1310 *
1311 * RETURN     :
1312 *==========================================================================*/
1313
1314void QCamera3HardwareInterface::get_metadata_vendor_tag_ops(
1315                const struct camera3_device *device,
1316                vendor_tag_query_ops_t* ops)
1317{
1318    QCamera3HardwareInterface *hw =
1319        reinterpret_cast<QCamera3HardwareInterface *>(device->priv);
1320    if (!hw) {
1321        ALOGE("%s: NULL camera device", __func__);
1322        return;
1323    }
1324
1325    hw->getMetadataVendorTagOps(ops);
1326    return;
1327}
1328
1329/*===========================================================================
1330 * FUNCTION   : dump
1331 *
1332 * DESCRIPTION:
1333 *
1334 * PARAMETERS :
1335 *
1336 *
1337 * RETURN     :
1338 *==========================================================================*/
1339
1340void QCamera3HardwareInterface::dump(
1341                const struct camera3_device *device, int fd)
1342{
1343    QCamera3HardwareInterface *hw =
1344        reinterpret_cast<QCamera3HardwareInterface *>(device->priv);
1345    if (!hw) {
1346        ALOGE("%s: NULL camera device", __func__);
1347        return;
1348    }
1349
1350    hw->dump(fd);
1351    return;
1352}
1353
1354/*===========================================================================
1355 * FUNCTION   : close_camera_device
1356 *
1357 * DESCRIPTION:
1358 *
1359 * PARAMETERS :
1360 *
1361 *
1362 * RETURN     :
1363 *==========================================================================*/
1364int QCamera3HardwareInterface::close_camera_device(struct hw_device_t* device)
1365{
1366    int ret = NO_ERROR;
1367    QCamera3HardwareInterface *hw =
1368        reinterpret_cast<QCamera3HardwareInterface *>(
1369            reinterpret_cast<camera3_device_t *>(device)->priv);
1370    if (!hw) {
1371        ALOGE("NULL camera device");
1372        return BAD_VALUE;
1373    }
1374    delete hw;
1375    return ret;
1376}
1377
1378
1379}; //end namespace qcamera
1380