diff --git a/src/Handle.h b/src/Handle.h index 4496d81763..4b611f1f01 100644 --- a/src/Handle.h +++ b/src/Handle.h @@ -22,7 +22,7 @@ class SourceImpl; // Handle data layout: // Bits 0-15: Handle index -// Bits 16-23: Subindex (property only) +// Bits 16-23: Parent index (property only) // Bits 24-30: Type class Handle { @@ -52,7 +52,7 @@ class Handle { return; } m_handle = ((static_cast(type) & 0x7f) << 24) | - ((property & 0xff) << 16) | (index & 0xffff); + ((index & 0xff) << 16) | (property & 0xffff); } int GetIndex() const { return static_cast(m_handle) & 0xffff; } @@ -61,7 +61,10 @@ class Handle { } bool IsType(Type type) const { return type == GetType(); } int GetTypedIndex(Type type) const { return IsType(type) ? GetIndex() : -1; } - int GetSubIndex() const { return (static_cast(m_handle) >> 16) & 0xff; } + int GetParentIndex() const { + return IsType(Handle::kProperty) ? (static_cast(m_handle) >> 16) & 0xff + : -1; + } private: CS_Handle m_handle; diff --git a/src/cameraserver_cpp.cpp b/src/cameraserver_cpp.cpp index 6202f6a423..85596d4e9d 100644 --- a/src/cameraserver_cpp.cpp +++ b/src/cameraserver_cpp.cpp @@ -19,7 +19,7 @@ static std::shared_ptr GetPropertySource(CS_Property propertyHandle, int* propertyIndex, CS_Status* status) { Handle handle{propertyHandle}; - int i = handle.GetTypedIndex(Handle::kProperty); + int i = handle.GetParentIndex(); if (i < 0) { *status = CS_INVALID_HANDLE; return nullptr; @@ -29,7 +29,7 @@ static std::shared_ptr GetPropertySource(CS_Property propertyHandle, *status = CS_INVALID_HANDLE; return nullptr; } - *propertyIndex = handle.GetSubIndex(); + *propertyIndex = handle.GetIndex(); return data->source; } @@ -47,12 +47,11 @@ CS_PropertyType GetPropertyType(CS_Property property, CS_Status* status) { } std::string GetPropertyName(CS_Property property, CS_Status* status) { - llvm::SmallString<128> name; + llvm::SmallString<128> buf; int propertyIndex; auto source = GetPropertySource(property, &propertyIndex, status); if (!source) return std::string{}; - source->GetPropertyName(propertyIndex, name); - return name.str(); + return source->GetPropertyName(propertyIndex, buf); } llvm::StringRef GetPropertyName(CS_Property property, @@ -266,8 +265,15 @@ CS_Property GetSourceProperty(CS_Source source, llvm::StringRef name, llvm::ArrayRef EnumerateSourceProperties( CS_Source source, llvm::SmallVectorImpl& vec, CS_Status* status) { - // TODO - return llvm::ArrayRef{}; + auto data = Sources::GetInstance().Get(source); + if (!data) { + *status = CS_INVALID_HANDLE; + return 0; + } + llvm::SmallVector properties_buf; + for (auto property : data->source->EnumerateProperties(properties_buf)) + vec.push_back(Handle{source, property, Handle::kProperty}); + return vec; } CS_Source CopySource(CS_Source source, CS_Status* status) { diff --git a/src/cameraserver_oo.cpp b/src/cameraserver_oo.cpp index 2786462da6..ae81441aab 100644 --- a/src/cameraserver_oo.cpp +++ b/src/cameraserver_oo.cpp @@ -10,21 +10,23 @@ using namespace cs; std::vector VideoSource::EnumerateProperties() const { - std::vector properties; - llvm::SmallVector handles; + llvm::SmallVector handles_buf; CS_Status status = 0; - EnumerateSourceProperties(m_handle, handles, &status); + auto handles = EnumerateSourceProperties(m_handle, handles_buf, &status); + + std::vector properties; properties.reserve(handles.size()); - for (int handle : handles) + for (CS_Property handle : handles) properties.emplace_back(VideoProperty{handle}); return properties; } std::vector VideoSource::EnumerateSources() { - std::vector sources; - llvm::SmallVector handles; + llvm::SmallVector handles_buf; CS_Status status = 0; - ::cs::EnumerateSourceHandles(handles, &status); + auto handles = ::cs::EnumerateSourceHandles(handles_buf, &status); + + std::vector sources; sources.reserve(handles.size()); for (int handle : handles) sources.emplace_back(VideoSource{handle}); @@ -32,10 +34,11 @@ std::vector VideoSource::EnumerateSources() { } std::vector VideoSink::EnumerateSinks() { - std::vector sinks; - llvm::SmallVector handles; + llvm::SmallVector handles_buf; CS_Status status = 0; - ::cs::EnumerateSinkHandles(handles, &status); + auto handles = ::cs::EnumerateSinkHandles(handles_buf, &status); + + std::vector sinks; sinks.reserve(handles.size()); for (int handle : handles) sinks.emplace_back(VideoSink{handle});