Emilian Peev | e18057b | 2017-11-13 16:03:44 +0000 | [diff] [blame^] | 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@3.4-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_4 { |
| 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_3::implementation::CameraDeviceSession(device, deviceInfo, callback) { |
| 38 | } |
| 39 | |
| 40 | CameraDeviceSession::~CameraDeviceSession() { |
| 41 | } |
| 42 | |
| 43 | Return<void> CameraDeviceSession::configureStreams_3_4( |
| 44 | const V3_4::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 | const camera_metadata_t *paramBuffer = nullptr; |
| 81 | if (0 < requestedConfiguration.sessionParams.size()) { |
| 82 | ::android::hardware::camera::common::V1_0::helper::CameraMetadata sessionParams; |
| 83 | V3_2::implementation::convertFromHidl(requestedConfiguration.sessionParams, ¶mBuffer); |
| 84 | } |
| 85 | |
| 86 | camera3_stream_configuration_t stream_list{}; |
| 87 | hidl_vec<camera3_stream_t*> streams; |
| 88 | stream_list.session_parameters = paramBuffer; |
| 89 | if (!preProcessConfigurationLocked(requestedConfiguration.v3_2, &stream_list, &streams)) { |
| 90 | _hidl_cb(Status::INTERNAL_ERROR, outStreams); |
| 91 | return Void(); |
| 92 | } |
| 93 | |
| 94 | ATRACE_BEGIN("camera3->configure_streams"); |
| 95 | status_t ret = mDevice->ops->configure_streams(mDevice, &stream_list); |
| 96 | ATRACE_END(); |
| 97 | |
| 98 | // In case Hal returns error most likely it was not able to release |
| 99 | // the corresponding resources of the deleted streams. |
| 100 | if (ret == OK) { |
| 101 | postProcessConfigurationLocked(requestedConfiguration.v3_2); |
| 102 | } |
| 103 | |
| 104 | if (ret == -EINVAL) { |
| 105 | status = Status::ILLEGAL_ARGUMENT; |
| 106 | } else if (ret != OK) { |
| 107 | status = Status::INTERNAL_ERROR; |
| 108 | } else { |
| 109 | V3_3::implementation::convertToHidl(stream_list, &outStreams); |
| 110 | mFirstRequest = true; |
| 111 | } |
| 112 | |
| 113 | _hidl_cb(status, outStreams); |
| 114 | return Void(); |
| 115 | } |
| 116 | |
| 117 | } // namespace implementation |
| 118 | } // namespace V3_4 |
| 119 | } // namespace device |
| 120 | } // namespace camera |
| 121 | } // namespace hardware |
| 122 | } // namespace android |