📄 props-txt.txt
字号:
INSTANCE_DATA_OF_PROPERTY_SIZE(tf), // This is the size of the instance data (you must consider the size of the struct MINUS the size of the KSPROPERTY, that is ADDED by the IKsPropertySet::Set method )
&tf, // Here we need a pointer to the property (NOT instance) data, so the pointer to the full propertyt struct is required.
sizeof(tf)); // Here we need the size of the property (NOT instance) data, so the size of rhe full property struct is required.
if(FAILED(hr)) {
Log(__FUNC__,__LINE__,"KSPROPERTY_TUNER_FREQUENCY",hr);
break;
}
// The following code is an undocumented way we could try to use to determie if a signal is present!
KSPROPERTY_TUNER_STATUS_S ts;
DWORD Tries;
for (Tries = 0; Tries < 30 ; Tries++) {
ZeroMemory(&ts,sizeof(ts));
ts.PLLOffset = -100;
ts.SignalStrength = 0;
ret = 0;
hr=kps->Get(PSET_TUNER,
KSPROPERTY_TUNER_STATUS,
INSTANCE_DATA_OF_PROPERTY_PTR(&ts), // The KSPROPERTY first member of the struct is ADDED by the IKsPropertySet::Set method, so we must pass a pointer to the fisrt element following the KSPROPERTY struct member (this is called "the instance data in the DirectX SDK")
INSTANCE_DATA_OF_PROPERTY_SIZE(ts), // This is the size of the instance data (you must consider the size of the struct MINUS the size of the KSPROPERTY, that is ADDED by the IKsPropertySet::Set method )
&ts, // Here we need a pointer to the property (NOT instance) data, so the pointer to the full propertyt struct is required.
sizeof(ts), // Here we need the size of the property (NOT instance) data, so the size of rhe full property struct is required.
&ret);
if(FAILED(hr)) {
Log(__FUNC__,__LINE__,"KSPROPERTY_TUNER_STATUS",hr);
break;
}
if (!ts.Busy &&
(
(ts.CurrentFrequency != 0 && ts.Currentfrequency != Freq) ||
(ts.PllOffset != -100 && ts.PllOffset != 0) ||
(ts.SignalStrength != 0 && SignalStrength != -1)
)
)
{
SignalFound = TRUE;
break;
}
Sleep(10); // Wait 10 milliseconds to let PLL stabilize
}
}
break;
// This means the driver won't do autotuning, but offers PLL Offset information to adjust freq.
case KS_TUNER_STRATEGY_PLL:
{
// Set frequency.
KSPROPERTY_TUNER_FREQUENCY_S tf;
ZeroMemory(&tf,sizeof(tf));
tf.Frequency = Freq; // The frequency to set...
hr=kps->Set(PSET_TUNER,
KSPROPERTY_TUNER_FREQUENCY,
INSTANCE_DATA_OF_PROPERTY_PTR(&tf), // The KSPROPERTY first member of the struct is ADDED by the IKsPropertySet::Set method, so we must pass a pointer to the fisrt element following the KSPROPERTY struct member (this is called "the instance data in the DirectX SDK")
INSTANCE_DATA_OF_PROPERTY_SIZE(tf), // This is the size of the instance data (you must consider the size of the struct MINUS the size of the KSPROPERTY, that is ADDED by the IKsPropertySet::Set method )
&tf, // Here we need a pointer to the property (NOT instance) data, so the pointer to the full propertyt struct is required.
sizeof(tf)); // Here we need the size of the property (NOT instance) data, so the size of rhe full property struct is required.
if(FAILED(hr)) {
Log(__FUNC__,__LINE__,"KSPROPERTY_TUNER_FREQUENCY",hr);
break;
}
// Now, read the PLL offset information
KSPROPERTY_TUNER_STATUS_S ts;
DWORD Tries;
for (Tries = 0; Tries < 30 ; Tries++) {
ZeroMemory(&ts,sizeof(ts));
ret = 0;
hr=kps->Get(PSET_TUNER,
KSPROPERTY_TUNER_STATUS,
INSTANCE_DATA_OF_PROPERTY_PTR(&ts), // The KSPROPERTY first member of the struct is ADDED by the IKsPropertySet::Set method, so we must pass a pointer to the fisrt element following the KSPROPERTY struct member (this is called "the instance data in the DirectX SDK")
INSTANCE_DATA_OF_PROPERTY_SIZE(ts), // This is the size of the instance data (you must consider the size of the struct MINUS the size of the KSPROPERTY, that is ADDED by the IKsPropertySet::Set method )
&ts, // Here we need a pointer to the property (NOT instance) data, so the pointer to the full propertyt struct is required.
sizeof(ts), // Here we need the size of the property (NOT instance) data, so the size of rhe full property struct is required.
&ret);
if(FAILED(hr)) {
Log(__FUNC__,__LINE__,"KSPROPERTY_TUNER_STATUS",hr);
break;
}
if (!ts.Busy) {
break;
}
Sleep(10); // Wait 10 milliseconds to let PLL stabilize
}
if (Tries == 30) {
Log(__FUNC__,__LINE__,"PLL didn't stabilize",hr);
break;
}
// We have the PLLoffset information... Adjust freq and go on with tests!
// Set Frequency
ZeroMemory(&tf,sizeof(tf));
tf.Frequency = Freq + ts.PLLOffset * tmc.TuningGranularity;
hr=kps->Set(PSET_TUNER,
KSPROPERTY_TUNER_FREQUENCY,
INSTANCE_DATA_OF_PROPERTY_PTR(&tf), // The KSPROPERTY first member of the struct is ADDED by the IKsPropertySet::Set method, so we must pass a pointer to the fisrt element following the KSPROPERTY struct member (this is called "the instance data in the DirectX SDK")
INSTANCE_DATA_OF_PROPERTY_SIZE(tf), // This is the size of the instance data (you must consider the size of the struct MINUS the size of the KSPROPERTY, that is ADDED by the IKsPropertySet::Set method )
&tf, // Here we need a pointer to the property (NOT instance) data, so the pointer to the full propertyt struct is required.
sizeof(tf)); // Here we need the size of the property (NOT instance) data, so the size of rhe full property struct is required.
if(FAILED(hr)) {
Log(__FUNC__,__LINE__,"KSPROPERTY_TUNER_FREQUENCY",hr);
break;
}
// Read the Status again...
for (Tries = 0; Tries < 30 ; Tries++) {
ZeroMemory(&ts,sizeof(ts));
ret = 0;
hr=kps->Get(PSET_TUNER,
KSPROPERTY_TUNER_STATUS,
INSTANCE_DATA_OF_PROPERTY_PTR(&ts), // The KSPROPERTY first member of the struct is ADDED by the IKsPropertySet::Set method, so we must pass a pointer to the fisrt element following the KSPROPERTY struct member (this is called "the instance data in the DirectX SDK")
INSTANCE_DATA_OF_PROPERTY_SIZE(ts), // This is the size of the instance data (you must consider the size of the struct MINUS the size of the KSPROPERTY, that is ADDED by the IKsPropertySet::Set method )
&ts, // Here we need a pointer to the property (NOT instance) data, so the pointer to the full propertyt struct is required.
sizeof(ts), // Here we need the size of the property (NOT instance) data, so the size of rhe full property struct is required.
&ret);
if(FAILED(hr)) {
Log(__FUNC__,__LINE__,"KSPROPERTY_TUNER_STATUS",hr);
break;
}
if (!ts.Busy) {
break;
}
Sleep(10); // Wait 10 milliseconds to let PLL stabilize
}
if (Tries == 30) {
Log(__FUNC__,__LINE__,"PLL didn't stabilize",hr);
break;
} else {
if (ts.PLLOffset == 0) {
SignalFound = TRUE;
}
}
}
break;
// This means the driver won't do autotuning, but offers SignalStrenght information to adjust freq.
case KS_TUNER_STRATEGY_SIGNAL_STRENGTH:
{
KSPROPERTY_TUNER_FREQUENCY_S tf;
KSPROPERTY_TUNER_STATUS_S ts;
DWORD MaxSignalStrength = 0;
DWORD MaxSSFreq = 1;
DWORD f;
for (
f = Freq - 4 * tcm.TuningGranularity;
f < Freq + 5 * tcm.TuningGranularity;
f += tcm.TuningGranularity) {
// Set frequency.
ZeroMemory(&tf,sizeof(tf));
tf.Frequency = f; // The frequency to set...
hr=kps->Set(PSET_TUNER,
KSPROPERTY_TUNER_FREQUENCY,
INSTANCE_DATA_OF_PROPERTY_PTR(&tf), // The KSPROPERTY first member of the struct is ADDED by the IKsPropertySet::Set method, so we must pass a pointer to the fisrt element following the KSPROPERTY struct member (this is called "the instance data in the DirectX SDK")
INSTANCE_DATA_OF_PROPERTY_SIZE(tf), // This is the size of the instance data (you must consider the size of the struct MINUS the size of the KSPROPERTY, that is ADDED by the IKsPropertySet::Set method )
&tf, // Here we need a pointer to the property (NOT instance) data, so the pointer to the full propertyt struct is required.
sizeof(tf)); // Here we need the size of the property (NOT instance) data, so the size of rhe full property struct is required.
if(FAILED(hr)) {
Log(__FUNC__,__LINE__,"KSPROPERTY_TUNER_FREQUENCY",hr);
break;
}
// Now, read the SignalStrenght information
DWORD Tries;
for (Tries = 0; Tries < 30 ; Tries++) {
ZeroMemory(&ts,sizeof(ts));
ret = 0;
hr=kps->Get(PSET_TUNER,
KSPROPERTY_TUNER_STATUS,
INSTANCE_DATA_OF_PROPERTY_PTR(&ts), // The KSPROPERTY first member of the struct is ADDED by the IKsPropertySet::Set method, so we must pass a pointer to the fisrt element following the KSPROPERTY struct member (this is called "the instance data in the DirectX SDK")
INSTANCE_DATA_OF_PROPERTY_SIZE(ts), // This is the size of the instance data (you must consider the size of the struct MINUS the size of the KSPROPERTY, that is ADDED by the IKsPropertySet::Set method )
&ts, // Here we need a pointer to the property (NOT instance) data, so the pointer to the full propertyt struct is required.
sizeof(ts), // Here we need the size of the property (NOT instance) data, so the size of rhe full property struct is required.
&ret);
if(FAILED(hr)) {
Log(__FUNC__,__LINE__,"KSPROPERTY_TUNER_STATUS",hr);
break;
}
if (!ts.Busy) {
break;
}
Sleep(10); // Wait 10 milliseconds to let PLL stabilize
}
if (Tries == 30) {
Log(__FUNC__,__LINE__,"PLL didn't stabilize",hr);
break;
}
// Record the current freq. if the signal is greater
if (MaxSignalStrength < ts.SignalStrength) {
MaxSignalStrength = ts.SignalStrength;
MaxSSFreq = f;
}
}
// We have the best signal... Hope!
// Set the last selected freq.
ZeroMemory(&tf,sizeof(tf));
tf.Frequency = MaxSSFreq; // The best frequency...
hr=kps->Set(PSET_TUNER,
KSPROPERTY_TUNER_FREQUENCY,
INSTANCE_DATA_OF_PROPERTY_PTR(&tf), // The KSPROPERTY first member of the struct is ADDED by the IKsPropertySet::Set method, so we must pass a pointer to the fisrt element following the KSPROPERTY struct member (this is called "the instance data in the DirectX SDK")
INSTANCE_DATA_OF_PROPERTY_SIZE(tf), // This is the size of the instance data (you must consider the size of the struct MINUS the size of the KSPROPERTY, that is ADDED by the IKsPropertySet::Set method )
&tf, // Here we need a pointer to the property (NOT instance) data, so the pointer to the full propertyt struct is required.
sizeof(tf)); // Here we need the size of the property (NOT instance) data, so the size of rhe full property struct is required.
if(FAILED(hr)) {
Log(__FUNC__,__LINE__,"KSPROPERTY_TUNER_FREQUENCY",hr);
}
// Decide if we have a signal present!
SignalFound = (MaxSignalStrength != 0);
}
break;
}
// Release the interface, as we won't use it anymore.
kps->Release();
// return if signal was found
return SignalFound;
}
//---------------------------------------------------------------------------
double CTuner::GetFrequency(void)
{
IKsPropertySet *kps;
HRESULT hr = pTVTuner->QueryInterface(IID_IKsPropertySet,(void **)&kps);
if(hr==NOERROR)
{
KSPROPERTY_TUNER_STATUS_S ts;
ZeroMemory(&ts,sizeof(ts));
DWORD ret=0;
hr=kps->Get(PSET_TUNER,
KSPROPERTY_TUNER_STATUS,
INSTANCE_DATA_OF_PROPERTY_PTR(&ts), // The KSPROPERTY first member of the struct is ADDED by the IKsPropertySet::Set method, so we must pass a pointer to the fisrt element following the KSPROPERTY struct member (this is called "the instance data in the DirectX SDK")
INSTANCE_DATA_OF_PROPERTY_SIZE(ts), // This is the size of the instance data (you must consider the size of the struct MINUS the size of the KSPROPERTY, that is ADDED by the IKsPropertySet::Set method )
&ts, // Here we need a pointer to the property (NOT instance) data, so the pointer to the full propertyt struct is required.
sizeof(ts), // Here we need the size of the property (NOT instance) data, so the size of rhe full property struct is required.
&ret);
// Release the interface, as we won't use it anymore.
kps->Release();
if(FAILED(hr))Log(__FUNC__,__LINE__,"KSPROPERTY_TUNER_STATUS",hr);
// Return the actual frequency of the tuner
// (this is NOT the frequency you have set, it is the driver-adjusted
// frequency of the current tuned channel (if driver implements the KS_TUNER_STRATEGY_DRIVER_TUNES strategy)
return tss.CurrentFrequency/1000000.;
} else {
Log(__FUNC__,__LINE__,"pTVTuner->QueryInterface IID_IKsPropertySet",hr);
}
return 0.;
}
3. And also I use IKsPropertySet for check signal...
// There's no reliable way to check for a signal present...
// pTVTuner->SignalPresent() uses internally KSPROPERTY_TUNER_STATUS
// to check for that, or perhaps, uses a similar way as the one implemented in
// CTuner::SetFrequency (so requires to use method p鵵_Channel to work.
// I suggest to to use IAMAnalogVideoDecoder::HorizontalLocking() to determine
// if a video signal is present, or trust in the returned value of SetFrequency.
int CTuner::CheckSignal(int method)
{
HRESULT hr;
if(method!=2)
{
IKsPropertySet *kps;
KSPROPERTY_TUNER_STATUS_S tss;
hr=pTVTuner->QueryInterface(IID_IKsPropertySet,(void **)&kps);
if(hr==NOERROR)
{
ZeroMemory(&tss,sizeof(tss));
DWORD ret=0;
hr=kps->Get(PSET_TUNER,
KSPROPERTY_TUNER_STATUS,
INSTANCE_DATA_OF_PROPERTY_PTR(&tss), // The KSPROPERTY first member of the struct is ADDED by the IKsPropertySet::Set method, so we must pass a pointer to the fisrt element following the KSPROPERTY struct member (this is called "the instance data in the DirectX SDK")
INSTANCE_DATA_OF_PROPERTY_SIZE(tss), // This is the size of the instance data (you must consider the size of the struct MINUS the size of the KSPROPERTY, that is ADDED by the IKsPropertySet::Set method )
&tss, // Here we need a pointer to the property (NOT instance) data, so the pointer to the full propertyt struct is required.
sizeof(tss), // Here we need the size of the property (NOT instance) data, so the size of rhe full property struct is required.
&ret);
// Release the interface, as we won't use it anymore.
kps->Release();
if(FAILED(hr))Log(__FUNC__,__LINE__,"KSPROPERTY_TUNER_STATUS",hr);
return tss.PLLOffset;
}else Log(__FUNC__,__LINE__,"pTVTuner->QueryInterface IID_IKsPropertySet",hr);
}
else
{
long SignalStrength = AMTUNER_NOSIGNAL;
hr=pTVTuner->SignalPresent(&SignalStrength);
if(FAILED(hr))Log(__FUNC__,__LINE__,"pTVTuner->SignalPresent failed",hr);
return SignalStrength;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -