Home | History | Annotate | Download | only in default
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #define LOG_TAG "CamDevSession (at) 3.3-impl"
     18 #include <android/log.h>
     19 
     20 #include <set>
     21 #include <utils/Trace.h>
     22 #include <hardware/gralloc.h>
     23 #include <hardware/gralloc1.h>
     24 #include "CameraDeviceSession.h"
     25 
     26 namespace android {
     27 namespace hardware {
     28 namespace camera {
     29 namespace device {
     30 namespace V3_3 {
     31 namespace implementation {
     32 
     33 CameraDeviceSession::CameraDeviceSession(
     34     camera3_device_t* device,
     35     const camera_metadata_t* deviceInfo,
     36     const sp<V3_2::ICameraDeviceCallback>& callback) :
     37         V3_2::implementation::CameraDeviceSession(device, deviceInfo, callback) {
     38 }
     39 
     40 CameraDeviceSession::~CameraDeviceSession() {
     41 }
     42 
     43 Return<void> CameraDeviceSession::configureStreams_3_3(
     44         const StreamConfiguration& requestedConfiguration,
     45         ICameraDeviceSession::configureStreams_3_3_cb _hidl_cb)  {
     46     Status status = initStatus();
     47     HalStreamConfiguration outStreams;
     48 
     49     // hold the inflight lock for entire configureStreams scope since there must not be any
     50     // inflight request/results during stream configuration.
     51     Mutex::Autolock _l(mInflightLock);
     52     if (!mInflightBuffers.empty()) {
     53         ALOGE("%s: trying to configureStreams while there are still %zu inflight buffers!",
     54                 __FUNCTION__, mInflightBuffers.size());
     55         _hidl_cb(Status::INTERNAL_ERROR, outStreams);
     56         return Void();
     57     }
     58 
     59     if (!mInflightAETriggerOverrides.empty()) {
     60         ALOGE("%s: trying to configureStreams while there are still %zu inflight"
     61                 " trigger overrides!", __FUNCTION__,
     62                 mInflightAETriggerOverrides.size());
     63         _hidl_cb(Status::INTERNAL_ERROR, outStreams);
     64         return Void();
     65     }
     66 
     67     if (!mInflightRawBoostPresent.empty()) {
     68         ALOGE("%s: trying to configureStreams while there are still %zu inflight"
     69                 " boost overrides!", __FUNCTION__,
     70                 mInflightRawBoostPresent.size());
     71         _hidl_cb(Status::INTERNAL_ERROR, outStreams);
     72         return Void();
     73     }
     74 
     75     if (status != Status::OK) {
     76         _hidl_cb(status, outStreams);
     77         return Void();
     78     }
     79 
     80     camera3_stream_configuration_t stream_list{};
     81     hidl_vec<camera3_stream_t*> streams;
     82     if (!preProcessConfigurationLocked(requestedConfiguration, &stream_list, &streams)) {
     83         _hidl_cb(Status::INTERNAL_ERROR, outStreams);
     84         return Void();
     85     }
     86 
     87     ATRACE_BEGIN("camera3->configure_streams");
     88     status_t ret = mDevice->ops->configure_streams(mDevice, &stream_list);
     89     ATRACE_END();
     90 
     91     // In case Hal returns error most likely it was not able to release
     92     // the corresponding resources of the deleted streams.
     93     if (ret == OK) {
     94         postProcessConfigurationLocked(requestedConfiguration);
     95     } else {
     96         postProcessConfigurationFailureLocked(requestedConfiguration);
     97     }
     98 
     99     if (ret == -EINVAL) {
    100         status = Status::ILLEGAL_ARGUMENT;
    101     } else if (ret != OK) {
    102         status = Status::INTERNAL_ERROR;
    103     } else {
    104         convertToHidl(stream_list, &outStreams);
    105         mFirstRequest = true;
    106     }
    107 
    108     _hidl_cb(status, outStreams);
    109     return Void();
    110 }
    111 
    112 } // namespace implementation
    113 }  // namespace V3_3
    114 }  // namespace device
    115 }  // namespace camera
    116 }  // namespace hardware
    117 }  // namespace android
    118