UsbCamera: Scale some properties to make them constently percentages.

The "raw" version of these properties are still available, just prefixed
with "raw_".
This commit is contained in:
Peter Johnson
2016-12-22 20:51:04 -08:00
parent 10b13da3da
commit ce69783871
8 changed files with 489 additions and 158 deletions

View File

@@ -53,6 +53,22 @@ class UsbCameraImpl : public SourceImpl {
class PropertyData : public PropertyBase {
public:
PropertyData() = default;
PropertyData(llvm::StringRef name_) : PropertyBase{name_} {}
// Normalized property constructor
PropertyData(llvm::StringRef name_, int rawIndex_,
const PropertyData& rawProp, int defaultValue_, int value_)
: PropertyBase(name_, rawProp.propKind, 1, defaultValue_, value_),
percentage{true},
propPair{rawIndex_},
id{rawProp.id},
type{rawProp.type} {
hasMinimum = true;
minimum = 0;
hasMaximum = true;
maximum = 100;
}
#ifdef __linux__
#ifdef VIDIOC_QUERY_EXT_CTRL
PropertyData(const struct v4l2_query_ext_ctrl& ctrl);
@@ -60,8 +76,14 @@ class UsbCameraImpl : public SourceImpl {
PropertyData(const struct v4l2_queryctrl& ctrl);
#endif
unsigned id; // implementation-level id
int type; // implementation type, not CS_PropertyKind!
// If this is a percentage (rather than raw) property
bool percentage{false};
// If not 0, index of corresponding raw/percentage property
int propPair{0};
unsigned id{0}; // implementation-level id
int type{0}; // implementation type, not CS_PropertyKind!
};
// Messages passed to/from camera thread
@@ -89,6 +111,9 @@ class UsbCameraImpl : public SourceImpl {
};
protected:
std::unique_ptr<PropertyBase> CreateEmptyProperty(
llvm::StringRef name) const override;
// Cache properties. Immediately successful if properties are already cached.
// If they are not, tries to connect to the camera to do so; returns false and
// sets status to CS_SOURCE_IS_DISCONNECTED if that too fails.
@@ -126,12 +151,27 @@ class UsbCameraImpl : public SourceImpl {
void DeviceSetMode();
void DeviceSetFPS();
void DeviceCacheMode();
void DeviceCacheProperty(std::unique_ptr<PropertyData> prop);
void DeviceCacheProperty(std::unique_ptr<PropertyData> rawProp);
void DeviceCacheProperties();
void DeviceCacheVideoModes();
bool DeviceGetProperty(PropertyData* prop);
bool DeviceSetProperty(std::unique_lock<std::mutex>& lock,
const PropertyData& prop);
bool DeviceSetProperty(std::unique_lock<std::mutex>& lock,
const PropertyData& prop, int value,
llvm::StringRef valueStr);
// Command helper functions
CS_StatusValue DeviceCmdSetProperty(std::unique_lock<std::mutex>& lock,
int property, bool setString, int value,
llvm::StringRef valueStr);
// Property helper functions
int RawToPercentage(const PropertyData& rawProp, int rawValue);
int PercentageToRaw(const PropertyData& rawProp, int percentValue);
void UpdatePropertyValue(int property, bool setString, int value,
llvm::StringRef valueStr);
void NotifyPropertyCreated(int propIndex, PropertyData& prop);
//
// Variables only used within camera thread