1 /*
2  * Copyright (C) 2022 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 #include "GrallocSensorBuffer.h"
18 
19 namespace android {
20 
~GrallocSensorBuffer()21 GrallocSensorBuffer::~GrallocSensorBuffer() {
22   if (stream_buffer.buffer != nullptr) {
23     importer_->unlock(stream_buffer.buffer);
24   }
25 
26   if (acquire_fence_fd >= 0) {
27     importer_->closeFence(acquire_fence_fd);
28   }
29 
30   if ((stream_buffer.status != BufferStatus::kOk) &&
31       (callback.notify != nullptr) && (!is_failed_request)) {
32     NotifyMessage msg = {
33         .type = MessageType::kError,
34         .message.error = {.frame_number = frame_number,
35                           .error_stream_id = stream_buffer.stream_id,
36                           .error_code = ErrorCode::kErrorBuffer}};
37     callback.notify(pipeline_id, msg);
38   }
39 
40   if (callback.process_pipeline_result != nullptr) {
41     auto result = std::make_unique<HwlPipelineResult>();
42     result->camera_id = camera_id;
43     result->pipeline_id = pipeline_id;
44     result->frame_number = frame_number;
45     result->partial_result = 0;
46 
47     stream_buffer.acquire_fence = stream_buffer.release_fence = nullptr;
48     if (is_input) {
49       result->input_buffers.push_back(stream_buffer);
50     } else {
51       result->output_buffers.push_back(stream_buffer);
52     }
53     callback.process_pipeline_result(std::move(result));
54   }
55 }
56 
57 }  // namespace android
58