blob: 11dc3a6b79d2c07bb2ad30bb6d86fe471d249e57 [file] [log] [blame]
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Util.h"
#include <unistd.h>
#include "jpeglib.h"
namespace android {
namespace companion {
namespace virtualcamera {
// Lower bound for maximal supported texture size is at least 2048x2048
// but on most platforms will be more.
// TODO(b/301023410) - Query actual max texture size.
constexpr int kMaxTextureSize = 2048;
constexpr int kLibJpegDctSize = DCTSIZE;
using ::aidl::android::companion::virtualcamera::Format;
using ::aidl::android::hardware::common::NativeHandle;
sp<Fence> importFence(const NativeHandle& aidlHandle) {
if (aidlHandle.fds.size() != 1) {
return sp<Fence>::make();
}
return sp<Fence>::make(::dup(aidlHandle.fds[0].get()));
}
// Returns true if specified format is supported for virtual camera input.
bool isFormatSupportedForInput(const int width, const int height,
const Format format) {
if (format != Format::YUV_420_888) {
// For now only YUV_420_888 is supported for input.
return false;
}
if (width <= 0 || height <= 0 || width > kMaxTextureSize ||
height > kMaxTextureSize) {
return false;
}
if (width % kLibJpegDctSize != 0 || height % kLibJpegDctSize != 0) {
// Input dimension needs to be multiple of libjpeg DCT size.
// TODO(b/301023410) This restriction can be removed once we add support for
// unaligned jpeg compression.
return false;
}
return true;
}
} // namespace virtualcamera
} // namespace companion
} // namespace android