Skip to content

Commit

Permalink
Add support for CameraControl and VideoProcAmp properties
Browse files Browse the repository at this point in the history
  • Loading branch information
exeldro authored and jp9000 committed Jun 15, 2022
1 parent ed02c35 commit 8f2ef91
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
18 changes: 18 additions & 0 deletions dshowcapture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ struct AudioConfig : Config {
AudioMode mode = AudioMode::Capture;
};

struct VideoDeviceProperty {
long property;
long flags;
long val;
long min;
long max;
long step;
long def;
};

class DSHOWCAPTURE_EXPORT Device {
HDevice *context;

Expand All @@ -224,6 +234,10 @@ class DSHOWCAPTURE_EXPORT Device {

bool SetVideoConfig(VideoConfig *config);
bool SetAudioConfig(AudioConfig *config);
bool SetCameraControlProperties(
std::vector<VideoDeviceProperty> *properties);
bool
SetVideoProcAmpProperties(std::vector<VideoDeviceProperty> *properties);

/**
* Connects all the configured filters together.
Expand All @@ -237,6 +251,10 @@ class DSHOWCAPTURE_EXPORT Device {

bool GetVideoConfig(VideoConfig &config) const;
bool GetAudioConfig(AudioConfig &config) const;
bool GetCameraControlProperties(
std::vector<VideoDeviceProperty> &properties) const;
bool GetVideoProcAmpProperties(
std::vector<VideoDeviceProperty> &properties) const;
bool GetVideoDeviceId(DeviceId &id) const;
bool GetAudioDeviceId(DeviceId &id) const;

Expand Down
85 changes: 85 additions & 0 deletions source/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,91 @@ bool HDevice::SetVideoConfig(VideoConfig *config)
return true;
}

bool HDevice::SetCameraControlProperties(
std::vector<VideoDeviceProperty> *properties)
{
if (videoFilter == nullptr)
return false;

ComQIPtr<IAMCameraControl> pCameraControl = videoFilter;
if (!pCameraControl)
return false;

for (const auto &prop : *properties) {
pCameraControl->Set(prop.property, prop.val, prop.flags);
}
return true;
}

bool HDevice::SetVideoProcAmpProperties(
std::vector<VideoDeviceProperty> *properties)
{
if (videoFilter == nullptr)
return false;

ComQIPtr<IAMVideoProcAmp> pVideoProcAmp = videoFilter;
if (!pVideoProcAmp)
return false;

for (const auto &prop : *properties) {
pVideoProcAmp->Set(prop.property, prop.val, prop.flags);
}
return true;
}

bool HDevice::GetCameraControlProperties(
std::vector<VideoDeviceProperty> &properties) const
{

if (videoFilter == nullptr)
return false;

ComQIPtr<IAMCameraControl> pCameraControl = videoFilter;
if (!pCameraControl)
return false;

for (long i = 0; i < 256; i++) {
long flags, val;
auto hr = pCameraControl->Get(i, &val, &flags);
if (FAILED(hr))
continue;
VideoDeviceProperty p{};
p.property = i;
p.flags = flags;
p.val = val;
hr = pCameraControl->GetRange(i, &p.min, &p.max, &p.step,
&p.def, &flags);
properties.push_back(p);
}
return true;
}

bool HDevice::GetVideoProcAmpProperties(
std::vector<VideoDeviceProperty> &properties) const
{
if (videoFilter == nullptr)
return false;

ComQIPtr<IAMVideoProcAmp> pVideoProcAmp = videoFilter;
if (!pVideoProcAmp)
return false;

for (long i = 0; i < 256; i++) {
long flags, val;
auto hr = pVideoProcAmp->Get(i, &val, &flags);
if (FAILED(hr))
continue;
VideoDeviceProperty p{};
p.property = i;
p.flags = flags;
p.val = val;
hr = pVideoProcAmp->GetRange(i, &p.min, &p.max, &p.step, &p.def,
&flags);
properties.push_back(p);
}
return true;
}

bool HDevice::SetupExceptionAudioCapture(IPin *pin)
{
ComPtr<IEnumMediaTypes> enumMediaTypes;
Expand Down
8 changes: 8 additions & 0 deletions source/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ struct HDevice {

bool SetVideoConfig(VideoConfig *config);
bool SetAudioConfig(AudioConfig *config);
bool SetCameraControlProperties(
std::vector<VideoDeviceProperty> *properties);
bool
SetVideoProcAmpProperties(std::vector<VideoDeviceProperty> *properties);
bool GetCameraControlProperties(
std::vector<VideoDeviceProperty> &properties) const;
bool GetVideoProcAmpProperties(
std::vector<VideoDeviceProperty> &properties) const;

bool CreateGraph();
bool FindCrossbar(IBaseFilter *filter, IBaseFilter **crossbar);
Expand Down
23 changes: 23 additions & 0 deletions source/dshowcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ bool Device::SetAudioConfig(AudioConfig *config)
return context->SetAudioConfig(config);
}

bool Device::SetCameraControlProperties(
std::vector<VideoDeviceProperty> *properties)
{
return context->SetCameraControlProperties(properties);
}
bool Device::SetVideoProcAmpProperties(
std::vector<VideoDeviceProperty> *properties)
{
return context->SetVideoProcAmpProperties(properties);
}

bool Device::ConnectFilters()
{
return context->ConnectFilters();
Expand All @@ -93,6 +104,18 @@ bool Device::GetVideoConfig(VideoConfig &config) const
return true;
}

bool Device::GetCameraControlProperties(
std::vector<VideoDeviceProperty> &properties) const
{
return context->GetCameraControlProperties(properties);
}

bool Device::GetVideoProcAmpProperties(
std::vector<VideoDeviceProperty> &properties) const
{
return context->GetVideoProcAmpProperties(properties);
}

bool Device::GetAudioConfig(AudioConfig &config) const
{
if (context->audioCapture == NULL)
Expand Down

0 comments on commit 8f2ef91

Please sign in to comment.