blob: 00708d40932fc99c47d62a8dad1b98244828d5a8 [file] [log] [blame] [edit]
/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef CAMERA_HAL_FAKE_HAL_SPEC_H_
#define CAMERA_HAL_FAKE_HAL_SPEC_H_
#include <optional>
#include <utility>
#include <variant>
#include <vector>
#include <base/files/file_path.h>
#include <base/values.h>
namespace cros {
// Specify how to scale the given frame image into target resolution.
enum class ScaleMode {
// Stretch the image to the target resolution.
kStretch,
// Resize the image to the largest size that will fit in the target
// resolution while maintaining the aspect ratio. The result image will be
// center aligned and outside area filled by black.
kContain,
// Resize the image to the smallest size that will cover the target
// resolution while maintaining the aspect ratio. The result image will be
// center aligned and the excessive area trimmed.
kCover,
};
// Specify how to loop the given video.
enum class LoopMode {
// Loop the video normally.
kLoop,
// Loop the video back and forth between the first and the last frame. If the
// video frames are [1,2,...,N], then the frames played back will be
// [1,2,...,N-1,N,N-1,...,2,1,2,...]
kPingPong,
};
struct SupportedFormatSpec {
int width = 0;
int height = 0;
std::vector<std::pair<int, int>> fps_ranges;
bool operator==(const SupportedFormatSpec& rhs) const {
return width == rhs.width && height == rhs.height &&
fps_ranges == rhs.fps_ranges;
}
bool operator!=(const SupportedFormatSpec& rhs) const {
return !(*this == rhs);
}
};
struct FramesFileSpec {
base::FilePath path;
ScaleMode scale_mode;
// How to loop if the given file is video. Has no effect on image file.
LoopMode loop_mode;
bool operator==(const FramesFileSpec& rhs) const {
return path == rhs.path && scale_mode == rhs.scale_mode &&
loop_mode == rhs.loop_mode;
}
bool operator!=(const FramesFileSpec& rhs) const { return !(*this == rhs); }
};
struct FramesTestPatternSpec {
bool use_solid_color_bar = false;
bool operator==(const FramesTestPatternSpec& rhs) const { return true; }
bool operator!=(const FramesTestPatternSpec& rhs) const {
return !(*this == rhs);
}
};
using FramesSpec = std::variant<FramesFileSpec, FramesTestPatternSpec>;
struct CameraSpec {
int id = 0;
bool connected = false;
std::vector<SupportedFormatSpec> supported_formats;
FramesSpec frames = FramesTestPatternSpec();
// When set, BLOB will be of a solid color (black), |frames| will be ignored.
bool solid_color_blob = false;
};
struct HalSpec {
std::vector<CameraSpec> cameras;
};
std::optional<HalSpec> ParseHalSpecFromJsonValue(
const base::Value::Dict& value);
} // namespace cros
#endif // CAMERA_HAL_FAKE_HAL_SPEC_H_