2016-08-19 23:05:28 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2016. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "cameraserver_cpp.h"
|
|
|
|
|
|
2016-09-05 12:00:04 -07:00
|
|
|
#include "llvm/SmallString.h"
|
|
|
|
|
|
|
|
|
|
#include "SinkImpl.h"
|
|
|
|
|
#include "SourceImpl.h"
|
|
|
|
|
#include "Handle.h"
|
2016-08-19 23:05:28 -07:00
|
|
|
|
|
|
|
|
using namespace cs;
|
|
|
|
|
|
2016-09-05 12:00:04 -07:00
|
|
|
static std::shared_ptr<SourceImpl> GetPropertySource(CS_Property propertyHandle,
|
|
|
|
|
int* propertyIndex,
|
|
|
|
|
CS_Status* status) {
|
|
|
|
|
Handle handle{propertyHandle};
|
|
|
|
|
int i = handle.GetTypedIndex(Handle::kProperty);
|
|
|
|
|
if (i < 0) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
auto data = Sources::GetInstance().Get(Handle{i, Handle::kSource});
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
*propertyIndex = handle.GetSubIndex();
|
|
|
|
|
return data->source;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
namespace cs {
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Property Functions
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
CS_PropertyType GetPropertyType(CS_Property property, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return CS_PROP_NONE;
|
|
|
|
|
return source->GetPropertyType(propertyIndex);
|
2016-08-25 23:13:48 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-26 08:19:28 -07:00
|
|
|
std::string GetPropertyName(CS_Property property, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
llvm::SmallString<128> name;
|
|
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return std::string{};
|
|
|
|
|
source->GetPropertyName(propertyIndex, name);
|
|
|
|
|
return name.str();
|
2016-08-26 08:19:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetPropertyName(CS_Property property, llvm::SmallVectorImpl<char>& name,
|
|
|
|
|
CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return;
|
|
|
|
|
source->GetPropertyName(propertyIndex, name);
|
2016-08-26 08:19:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
bool GetBooleanProperty(CS_Property property, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return false;
|
|
|
|
|
return source->GetBooleanProperty(propertyIndex);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void SetBooleanProperty(CS_Property property, bool value, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return;
|
|
|
|
|
source->SetBooleanProperty(propertyIndex, value);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
double GetDoubleProperty(CS_Property property, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return false;
|
|
|
|
|
return source->GetDoubleProperty(propertyIndex);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void SetDoubleProperty(CS_Property property, double value, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return;
|
|
|
|
|
source->SetDoubleProperty(propertyIndex, value);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
double GetDoublePropertyMin(CS_Property property, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return 0.0;
|
|
|
|
|
return source->GetPropertyMin(propertyIndex);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
double GetDoublePropertyMax(CS_Property property, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return 0.0;
|
|
|
|
|
return source->GetPropertyMax(propertyIndex);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
std::string GetStringProperty(CS_Property property, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
llvm::SmallString<128> value;
|
|
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return std::string{};
|
|
|
|
|
source->GetStringProperty(propertyIndex, value);
|
|
|
|
|
return value.str();
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void GetStringProperty(CS_Property property, llvm::SmallVectorImpl<char>& value,
|
|
|
|
|
CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return;
|
|
|
|
|
source->GetStringProperty(propertyIndex, value);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void SetStringProperty(CS_Property property, llvm::StringRef value,
|
|
|
|
|
CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return;
|
|
|
|
|
source->SetStringProperty(propertyIndex, value);
|
2016-08-25 23:13:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GetEnumProperty(CS_Property property, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return 0;
|
|
|
|
|
return source->GetEnumProperty(propertyIndex);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void SetEnumProperty(CS_Property property, int value, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return;
|
|
|
|
|
source->SetEnumProperty(propertyIndex, value);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
std::vector<std::string> GetEnumPropertyChoices(CS_Property property,
|
|
|
|
|
CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
int propertyIndex;
|
|
|
|
|
auto source = GetPropertySource(property, &propertyIndex, status);
|
|
|
|
|
if (!source) return std::vector<std::string>{};
|
|
|
|
|
return source->GetEnumPropertyChoices(propertyIndex);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
//
|
|
|
|
|
// Source Creation Functions
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
CS_Source CreateUSBSourceDev(llvm::StringRef name, int dev, CS_Status* status) {
|
|
|
|
|
return 0; // TODO
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
CS_Source CreateUSBSourcePath(llvm::StringRef name, llvm::StringRef path,
|
|
|
|
|
CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
return 0; // TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
CS_Source CreateHTTPSource(llvm::StringRef name, llvm::StringRef url,
|
|
|
|
|
CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
return 0; // TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
CS_Source CreateCvSource(llvm::StringRef name, int numChannels,
|
|
|
|
|
CS_Status* status) {
|
|
|
|
|
return 0; // TODO
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
//
|
|
|
|
|
// Source Functions
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
std::string GetSourceName(CS_Source source, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
auto data = Sources::GetInstance().Get(source);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return std::string{};
|
|
|
|
|
}
|
|
|
|
|
return data->source->GetName();
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-09-05 12:00:04 -07:00
|
|
|
void GetSourceName(CS_Source source, llvm::SmallVectorImpl<char>& name,
|
2016-08-25 23:13:48 -07:00
|
|
|
CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
auto data = Sources::GetInstance().Get(source);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
auto str = data->source->GetName();
|
|
|
|
|
name.append(str.begin(), str.end());
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
std::string GetSourceDescription(CS_Source source, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
llvm::SmallString<128> desc;
|
|
|
|
|
auto data = Sources::GetInstance().Get(source);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return std::string{};
|
|
|
|
|
}
|
|
|
|
|
data->source->GetDescription(desc);
|
|
|
|
|
return desc.str();
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void GetSourceDescription(CS_Source source, llvm::SmallVectorImpl<char>& desc,
|
|
|
|
|
CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
auto data = Sources::GetInstance().Get(source);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
data->source->GetDescription(desc);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
uint64_t GetSourceLastFrameTime(CS_Source source, CS_Status* status) {
|
|
|
|
|
return 0; // TODO
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
int GetSourceNumChannels(CS_Source source, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
auto data = Sources::GetInstance().Get(source);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return data->source->GetNumChannels();
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
bool IsSourceConnected(CS_Source source, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
auto data = Sources::GetInstance().Get(source);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return data->source->IsConnected();
|
2016-08-25 23:13:48 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-26 09:24:18 -07:00
|
|
|
CS_Property GetSourceProperty(CS_Source source, llvm::StringRef name,
|
|
|
|
|
CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
auto data = Sources::GetInstance().Get(source);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
int property = data->source->GetProperty(name);
|
|
|
|
|
if (property < 0) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return Handle{source, property, Handle::kProperty};
|
2016-08-26 09:24:18 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-26 08:19:28 -07:00
|
|
|
void EnumerateSourceProperties(CS_Source source,
|
|
|
|
|
llvm::SmallVectorImpl<CS_Property>& properties,
|
|
|
|
|
CS_Status* status) {
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
CS_Source CopySource(CS_Source source, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
if (source == 0) return 0;
|
|
|
|
|
auto data = Sources::GetInstance().Get(source);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
data->refCount++;
|
|
|
|
|
return source;
|
2016-08-25 23:13:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ReleaseSource(CS_Source source, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
if (source == 0) return;
|
|
|
|
|
auto& inst = Sources::GetInstance();
|
|
|
|
|
auto data = inst.Get(source);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (--(data->refCount) == 0) inst.Free(source);
|
2016-08-25 23:13:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// OpenCV Source Functions
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
void PutSourceImage(CS_Source source, int channel, cv::Mat* image,
|
|
|
|
|
CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void NotifySourceFrame(CS_Source source, CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void PutSourceFrame(CS_Source source, cv::Mat* image, CS_Status* status) {
|
|
|
|
|
// TODO
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void NotifySourceError(CS_Source source, llvm::StringRef msg,
|
|
|
|
|
CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void SetSourceConnected(CS_Source source, bool connected, CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
CS_Property CreateSourceProperty(CS_Source source, llvm::StringRef name,
|
|
|
|
|
CS_PropertyType type, CS_Status* status) {
|
|
|
|
|
return 0; // TODO
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
CS_Property CreateSourcePropertyCallback(
|
|
|
|
|
CS_Source source, llvm::StringRef name, CS_PropertyType type,
|
2016-08-26 08:19:28 -07:00
|
|
|
std::function<void(CS_Property property)> onChange, CS_Status* status) {
|
2016-08-25 23:13:48 -07:00
|
|
|
return 0; // TODO
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-26 08:19:28 -07:00
|
|
|
void RemoveSourceProperty(CS_Source source, CS_Property property,
|
|
|
|
|
CS_Status* status) {
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void RemoveSourceProperty(CS_Source source, llvm::StringRef name,
|
|
|
|
|
CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
//
|
|
|
|
|
// Sink Creation Functions
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
CS_Sink CreateCvSink(llvm::StringRef name, CS_Status* status) {
|
|
|
|
|
return 0; // TODO
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
CS_Sink CreateCvSinkCallback(llvm::StringRef name,
|
|
|
|
|
std::function<void(uint64_t time)> processFrame,
|
|
|
|
|
CS_Status* status) {
|
|
|
|
|
return 0; // TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Sink Functions
|
|
|
|
|
//
|
|
|
|
|
std::string GetSinkName(CS_Sink sink, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
auto data = Sinks::GetInstance().Get(sink);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return std::string{};
|
|
|
|
|
}
|
|
|
|
|
return data->sink->GetName();
|
2016-08-25 23:13:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetSinkName(CS_Sink sink, llvm::SmallVectorImpl<char>& name,
|
|
|
|
|
CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
auto data = Sinks::GetInstance().Get(sink);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
auto str = data->sink->GetName();
|
|
|
|
|
name.append(str.begin(), str.end());
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
std::string GetSinkDescription(CS_Sink sink, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
llvm::SmallString<128> desc;
|
|
|
|
|
auto data = Sinks::GetInstance().Get(sink);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return std::string{};
|
|
|
|
|
}
|
|
|
|
|
data->sink->GetDescription(desc);
|
|
|
|
|
return desc.str();
|
2016-08-25 23:13:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetSinkDescription(CS_Sink sink, llvm::SmallVectorImpl<char>& desc,
|
|
|
|
|
CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
auto data = Sinks::GetInstance().Get(sink);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
data->sink->GetDescription(desc);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void SetSinkSource(CS_Sink sink, CS_Source source, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
auto data = Sinks::GetInstance().Get(sink);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
auto sourceData = Sources::GetInstance().Get(source);
|
|
|
|
|
if (!sourceData) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
data->sink->SetSource(sourceData->source);
|
|
|
|
|
data->sourceHandle.store(source);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
CS_Source GetSinkSource(CS_Sink sink, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
auto data = Sinks::GetInstance().Get(sink);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return data->sourceHandle.load();
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-26 09:24:18 -07:00
|
|
|
CS_Property GetSinkSourceProperty(CS_Sink sink, llvm::StringRef name,
|
|
|
|
|
CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
auto data = Sinks::GetInstance().Get(sink);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return GetSourceProperty(data->sourceHandle.load(), name, status);
|
2016-08-26 09:24:18 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
CS_Sink CopySink(CS_Sink sink, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
if (sink == 0) return 0;
|
|
|
|
|
auto data = Sinks::GetInstance().Get(sink);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
data->refCount++;
|
|
|
|
|
return sink;
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void ReleaseSink(CS_Sink sink, CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
if (sink == 0) return;
|
|
|
|
|
auto& inst = Sinks::GetInstance();
|
|
|
|
|
auto data = inst.Get(sink);
|
|
|
|
|
if (!data) {
|
|
|
|
|
*status = CS_INVALID_HANDLE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (--(data->refCount) == 0) inst.Free(sink);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
//
|
|
|
|
|
// OpenCV Sink Functions
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
uint64_t SinkWaitForFrame(CS_Sink sink, CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
return 0; // TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
bool GetSinkImage(CS_Sink sink, int channel, cv::Mat* image,
|
|
|
|
|
CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
return false; // TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
uint64_t GrabSinkFrame(CS_Sink sink, cv::Mat* image, CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
return 0; // TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
std::string GetSinkError(CS_Sink sink, CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
return ""; // TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 07:04:33 -07:00
|
|
|
void GetSinkError(CS_Sink sink, llvm::SmallVectorImpl<char>& msg,
|
2016-08-25 23:13:48 -07:00
|
|
|
CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void SetSinkEnabled(CS_Sink sink, bool enabled, CS_Status* status) {
|
|
|
|
|
// TODO
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
//
|
|
|
|
|
// Listener Functions
|
|
|
|
|
//
|
2016-08-19 23:05:28 -07:00
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
CS_Listener AddSourceListener(
|
|
|
|
|
std::function<void(llvm::StringRef name, CS_Source source, int event)>
|
2016-08-19 23:05:28 -07:00
|
|
|
callback,
|
2016-08-25 23:13:48 -07:00
|
|
|
int eventMask, CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
return 0; // TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void RemoveSourceListener(CS_Listener handle, CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
CS_Listener AddSinkListener(
|
|
|
|
|
std::function<void(llvm::StringRef name, CS_Sink sink, int event)> callback,
|
|
|
|
|
int eventMask, CS_Status* status) {
|
2016-08-19 23:05:28 -07:00
|
|
|
return 0; // TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void RemoveSinkListener(CS_Listener handle, CS_Status* status) {
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Utility Functions
|
|
|
|
|
//
|
|
|
|
|
|
2016-08-26 07:04:33 -07:00
|
|
|
std::vector<USBCameraInfo> EnumerateUSBCameras(CS_Status* status) {
|
|
|
|
|
return std::vector<USBCameraInfo>{}; // TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:13:48 -07:00
|
|
|
void EnumerateSourceHandles(llvm::SmallVectorImpl<CS_Source>& handles,
|
|
|
|
|
CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
Sources::GetInstance().GetAll(handles);
|
2016-08-19 23:05:28 -07:00
|
|
|
}
|
2016-08-25 23:13:48 -07:00
|
|
|
|
|
|
|
|
void EnumerateSinkHandles(llvm::SmallVectorImpl<CS_Sink>& handles,
|
|
|
|
|
CS_Status* status) {
|
2016-09-05 12:00:04 -07:00
|
|
|
Sinks::GetInstance().GetAll(handles);
|
2016-08-25 23:13:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace cs
|