Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 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 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 17 | #include "Util.h" |
| 18 | |
| 19 | #include <unistd.h> |
| 20 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame^] | 21 | #include "jpeglib.h" |
| 22 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 23 | namespace android { |
| 24 | namespace companion { |
| 25 | namespace virtualcamera { |
| 26 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame^] | 27 | // Lower bound for maximal supported texture size is at least 2048x2048 |
| 28 | // but on most platforms will be more. |
| 29 | // TODO(b/301023410) - Query actual max texture size. |
| 30 | constexpr int kMaxTextureSize = 2048; |
| 31 | constexpr int kLibJpegDctSize = DCTSIZE; |
| 32 | |
| 33 | using ::aidl::android::companion::virtualcamera::Format; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 34 | using ::aidl::android::hardware::common::NativeHandle; |
| 35 | |
| 36 | sp<Fence> importFence(const NativeHandle& aidlHandle) { |
| 37 | if (aidlHandle.fds.size() != 1) { |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 38 | return sp<Fence>::make(); |
| 39 | } |
| 40 | |
| 41 | return sp<Fence>::make(::dup(aidlHandle.fds[0].get())); |
| 42 | } |
| 43 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame^] | 44 | // Returns true if specified format is supported for virtual camera input. |
| 45 | bool isFormatSupportedForInput(const int width, const int height, |
| 46 | const Format format) { |
| 47 | if (format != Format::YUV_420_888) { |
| 48 | // For now only YUV_420_888 is supported for input. |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | if (width <= 0 || height <= 0 || width > kMaxTextureSize || |
| 53 | height > kMaxTextureSize) { |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | if (width % kLibJpegDctSize != 0 || height % kLibJpegDctSize != 0) { |
| 58 | // Input dimension needs to be multiple of libjpeg DCT size. |
| 59 | // TODO(b/301023410) This restriction can be removed once we add support for |
| 60 | // unaligned jpeg compression. |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | return true; |
| 65 | } |
| 66 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 67 | } // namespace virtualcamera |
| 68 | } // namespace companion |
| 69 | } // namespace android |