Skip to main content
本文から 542 文字削除
ソース リンク
user60510
user60510

C++

int SetValue(IBaseFilter * pMediaSource, int nodeId)
{
    HRESULT hRet;
    IKsTopologyInfo* ksTopology;
    IUnknown* unk;
    IKsControl* ksCnt;

    hRet = pMediaSource->QueryInterface(__uuidof(IKsTopologyInfo), (void**)&ksTopology);
    if (FAILED(hRet))
        return FALSE;

    hRet = ksTopology->CreateNodeInstance(nodeId, __uuidof(IUnknown), (VOID**)&unk);
    if (FAILED(hRet))
        return FALSE;

    hRet = unk->QueryInterface(__uuidof(IKsControl), (VOID**)&ksCnt);
    if (FAILED(hRet))
        return FALSE;

    return TRUE;
}

C#

C++

int SetValue(IBaseFilter * pMediaSource, int nodeId)
{
    HRESULT hRet;
    IKsTopologyInfo* ksTopology;
    IUnknown* unk;
    IKsControl* ksCnt;

    hRet = pMediaSource->QueryInterface(__uuidof(IKsTopologyInfo), (void**)&ksTopology);
    if (FAILED(hRet))
        return FALSE;

    hRet = ksTopology->CreateNodeInstance(nodeId, __uuidof(IUnknown), (VOID**)&unk);
    if (FAILED(hRet))
        return FALSE;

    hRet = unk->QueryInterface(__uuidof(IKsControl), (VOID**)&ksCnt);
    if (FAILED(hRet))
        return FALSE;

    return TRUE;
}

C#

C#

本文から 132 文字削除
ソース リンク
user60510
user60510
public Boolean SetValue(DirectShowLib.IBaseFilter pMediaSource, int nodeId)
{
    HRESULT hRet;
    DirectN.IKsTopologyInfo ksTopology;
    Guid iid;
    IntPtr pUnk1;
    IntPtr ppv1;
    object unk;

    pUnk1 = Marshal.GetComInterfaceForObject(pMediaSource, typeof(DirectShowLib.IBaseFilter));
    iid = new Guid("720D4AC0-7533-11D0-A5D6-28DB04C10000");
    ksTopology = pMediaSource as DirectN.IKsTopologyInfo;
    ppv1 = Marshal.GetComInterfaceForObject(ksTopology, typeof(DirectN.IKsTopologyInfo));

    hRet = Marshal.QueryInterface(pUnk1, ref iid, out ppv1);
    if (hRet != 0)
        return false;

    iid = new Guid("00000000-0000-0000-C000-000000000046");

    hRet = ksTopology.CreateNodeInstance((uint)nodeId, iid, out unk);
    if (hRet != 0)
        return false;

    IKsControl ksCnt;
    IntPtr pUnk2;
    IntPtr ppv2;

    pUnk2 = GCHandle.ToIntPtr(GCHandle.Alloc(unk));
    iid = new Guid("28F54685-06FD-11D2-B27A-00A0C9223196");
    ksCnt = unk as IKsControl;
    ppv2 = Marshal.GetComInterfaceForObject(ksCnt, typeof(IKsControl));

    hRet = Marshal.QueryInterface(pUnk2, ref iid, out ppv2);
    if (hRet != 0)
        return false;

    Marshal.FreeHGlobal(ppv2);
    Marshal.FreeHGlobal(pUnk2);
    Marshal.ReleaseComObject(ksCnt);

    Marshal.FreeHGlobal(ppv1);
    Marshal.FreeHGlobal(pUnk1);
    Marshal.ReleaseComObject(ksTopology);

    return true;
}
public Boolean SetValue(DirectShowLib.IBaseFilter pMediaSource, int nodeId)
{
    HRESULT hRet;
    DirectN.IKsTopologyInfo ksTopology;
    Guid iid;
    IntPtr pUnk1;
    IntPtr ppv1;
    object unk;

    pUnk1 = Marshal.GetComInterfaceForObject(pMediaSource, typeof(DirectShowLib.IBaseFilter));
    iid = new Guid("720D4AC0-7533-11D0-A5D6-28DB04C10000");
    ksTopology = pMediaSource as DirectN.IKsTopologyInfo;
    ppv1 = Marshal.GetComInterfaceForObject(ksTopology, typeof(DirectN.IKsTopologyInfo));

    hRet = Marshal.QueryInterface(pUnk1, ref iid, out ppv1);
    if (hRet != 0)
        return false;

    iid = new Guid("00000000-0000-0000-C000-000000000046");

    hRet = ksTopology.CreateNodeInstance((uint)nodeId, iid, out unk);
    if (hRet != 0)
        return false;

    IKsControl ksCnt;
    IntPtr pUnk2;
    IntPtr ppv2;

    pUnk2 = GCHandle.ToIntPtr(GCHandle.Alloc(unk));
    iid = new Guid("28F54685-06FD-11D2-B27A-00A0C9223196");
    ksCnt = unk as IKsControl;
    ppv2 = Marshal.GetComInterfaceForObject(ksCnt, typeof(IKsControl));

    hRet = Marshal.QueryInterface(pUnk2, ref iid, out ppv2);
    if (hRet != 0)
        return false;

    Marshal.FreeHGlobal(ppv2);
    Marshal.FreeHGlobal(pUnk2);
    Marshal.ReleaseComObject(ksCnt);

    Marshal.FreeHGlobal(ppv1);
    Marshal.FreeHGlobal(pUnk1);
    Marshal.ReleaseComObject(ksTopology);

    return true;
}
public Boolean SetValue(DirectShowLib.IBaseFilter pMediaSource, int nodeId)
{
    HRESULT hRet;
    DirectN.IKsTopologyInfo ksTopology;
    Guid iid;
    IntPtr pUnk1;
    IntPtr ppv1;
    object unk;

    pUnk1 = Marshal.GetComInterfaceForObject(pMediaSource, typeof(DirectShowLib.IBaseFilter));
    iid = new Guid("720D4AC0-7533-11D0-A5D6-28DB04C10000");
    ksTopology = pMediaSource as DirectN.IKsTopologyInfo;
    ppv1 = Marshal.GetComInterfaceForObject(ksTopology, typeof(DirectN.IKsTopologyInfo));

    hRet = Marshal.QueryInterface(pUnk1, ref iid, out ppv1);
    if (hRet != 0)
        return false;

    iid = new Guid("00000000-0000-0000-C000-000000000046");

    hRet = ksTopology.CreateNodeInstance((uint)nodeId, iid, out unk);
    if (hRet != 0)
        return false;

    IKsControl ksCnt;
    IntPtr pUnk2;
    IntPtr ppv2;

    pUnk2 = GCHandle.ToIntPtr(GCHandle.Alloc(unk));
    iid = new Guid("28F54685-06FD-11D2-B27A-00A0C9223196");
    ksCnt = unk as IKsControl;
    ppv2 = Marshal.GetComInterfaceForObject(ksCnt, typeof(IKsControl));

    hRet = Marshal.QueryInterface(pUnk2, ref iid, out ppv2);
    if (hRet != 0)
        return false;

    Marshal.ReleaseComObject(ksCnt);
    Marshal.ReleaseComObject(ksTopology);

    return true;
}
質問の簡略化
ソース リンク
user60510
user60510

UVC C#でIKsTopologyInfo, IKsControlを使用し、UVCカメラのExtension UnitにデータCOM API送信したい取得する

現在C#および.NET FrameworkでUVCカメラのExtension UnitにデータCOM API送信取得したいと考えております。

C++では下記リンクを参考にDirectShowのIKsTopologyInfoIKsControlインターフェイスを使用し、データの送受信COM API行う取得することができました。

int SetValue(IBaseFilter * pMediaSource, GUID cameraGuid, int nodeId, int propId, int transData)
{
    HRESULT hRet;
    IKsTopologyInfo* ksTopology;
    IUnknown* unk;
    IKsControl* ksCnt;

    hRet = pMediaSource->QueryInterface(__uuidof(IKsTopologyInfo), (void**)&ksTopology);
    if (FAILED(hRet))
        return FALSE;

    hRet = ksTopology->CreateNodeInstance(nodeId, __uuidof(IUnknown), (VOID**)&unk);
    if (FAILED(hRet))
        return FALSE;

    hRet = unk->QueryInterface(__uuidof(IKsControl), (VOID**)&ksCnt);
    if (FAILED(hRet))
        return FALSE;

    KSP_NODE prop;
    unsigned char propData[16];
    ULONG bytesReturned;

    prop.Property.Set = cameraGuid;
    prop.Property.Id = propId;
    prop.Property.Flags = KSPROPERTY_TYPE_SET | KSPROPERTY_TYPE_TOPOLOGY;
    prop.NodeId = nodeId;

    propData[0] = (unsigned char)transData & 0xff;
    propData[1] = 0;
    hRet = ksCnt->KsProperty((PKSPROPERTY)&prop, sizeof(prop), &propData[0], 1, &bytesReturned);

    ksCnt->Release();
    unk->Release();
    ksTopology->Release();

    if (FAILED(hRet))
        return FALSE;

    return TRUE;
}
public const int KSPROPERTY_TYPE_GET = 0x00000001;
public const int KSPROPERTY_TYPE_SET = 0x00000002;
public const int KSPROPERTY_TYPE_TOPOLOGY = 0x10000000;

public Boolean SetValue(DirectShowLib.IBaseFilter pMediaSource, Guid cameraGuid, int nodeId, int propId, int transData)
{
    HRESULT hRet;
    DirectN.IKsTopologyInfo ksTopology;
    Guid iid;
    IntPtr pUnk1;
    IntPtr ppv1;
    object unk;

    pUnk1 = Marshal.GetComInterfaceForObject(pMediaSource, typeof(DirectShowLib.IBaseFilter));
    iid = new Guid("720D4AC0-7533-11D0-A5D6-28DB04C10000");
    ksTopology = pMediaSource as DirectN.IKsTopologyInfo;
    ppv1 = Marshal.GetComInterfaceForObject(ksTopology, typeof(DirectN.IKsTopologyInfo));

    hRet = Marshal.QueryInterface(pUnk1, ref iid, out ppv1);
    if (hRet != 0)
        return false;

    iid = new Guid("00000000-0000-0000-C000-000000000046");

    hRet = ksTopology.CreateNodeInstance((uint)nodeId, iid, out unk);
    if (hRet != 0)
        return false;

    IKsControl ksCnt;
    IntPtr pUnk2;
    IntPtr ppv2;

    pUnk2 = GCHandle.ToIntPtr(GCHandle.Alloc(unk));
    iid = new Guid("28F54685-06FD-11D2-B27A-00A0C9223196");
    ksCnt = unk as IKsControl;
    ppv2 = Marshal.GetComInterfaceForObject(ksCnt, typeof(IKsControl));

    hRet = Marshal.QueryInterface(pUnk2, ref iid, out ppv2);
    if (hRet != 0)
        return false;

    __struct_ks_2__union_0__struct_0 st;
    KSIDENTIFIER property;
    KSP_NODE prop;

    byte[] data = new byte[16];
    IntPtr propData = IntPtr.Zero;
    uint bytesReturned = 0;

    st.Set = cameraGuid;
    st.Id = (uint)propId;
    st.Flags = KSPROPERTY_TYPE_SET | KSPROPERTY_TYPE_TOPOLOGY;

    property = new KSIDENTIFIER();
    property.__union_0.__field_0 = st;

    prop = new KSP_NODE();
    prop.Property = property;
    prop.NodeId = (uint)nodeId;

    data[0] = (byte)(transData & 0xff);
    data[1] = 0;
    propData = Marshal.AllocHGlobal(data.Length);
    Marshal.Copy(data, 0, propData, data.Length);
    hRet = ksCnt.KsProperty(ref prop.Property, (uint)Marshal.SizeOf(prop), out propData, 1, out bytesReturned);

    Marshal.FreeHGlobal(propDatappv2);
 
    Marshal.FreeHGlobal(pUnk2);
    Marshal.FreeHGlobalReleaseComObject(ppv2ksCnt); 

    Marshal.FreeHGlobal(pUnkppv1);
    Marshal.FreeHGlobal(ppvpUnk1);
 
    if Marshal.ReleaseComObject(hRet != 0ksTopology)
        return false;

    return true;
}

UVCカメラのExtension Unitにデータ送信したい

現在C#および.NET FrameworkでUVCカメラのExtension Unitにデータ送信したいと考えております。

C++では下記リンクを参考にDirectShowのIKsTopologyInfoIKsControlインターフェイスを使用し、データの送受信行うことができました。

int SetValue(IBaseFilter * pMediaSource, GUID cameraGuid, int nodeId, int propId, int transData)
{
    HRESULT hRet;
    IKsTopologyInfo* ksTopology;
    IUnknown* unk;
    IKsControl* ksCnt;

    hRet = pMediaSource->QueryInterface(__uuidof(IKsTopologyInfo), (void**)&ksTopology);
    if (FAILED(hRet))
        return FALSE;

    hRet = ksTopology->CreateNodeInstance(nodeId, __uuidof(IUnknown), (VOID**)&unk);
    if (FAILED(hRet))
        return FALSE;

    hRet = unk->QueryInterface(__uuidof(IKsControl), (VOID**)&ksCnt);
    if (FAILED(hRet))
        return FALSE;

    KSP_NODE prop;
    unsigned char propData[16];
    ULONG bytesReturned;

    prop.Property.Set = cameraGuid;
    prop.Property.Id = propId;
    prop.Property.Flags = KSPROPERTY_TYPE_SET | KSPROPERTY_TYPE_TOPOLOGY;
    prop.NodeId = nodeId;

    propData[0] = (unsigned char)transData & 0xff;
    propData[1] = 0;
    hRet = ksCnt->KsProperty((PKSPROPERTY)&prop, sizeof(prop), &propData[0], 1, &bytesReturned);

    ksCnt->Release();
    unk->Release();
    ksTopology->Release();

    if (FAILED(hRet))
        return FALSE;

    return TRUE;
}
public const int KSPROPERTY_TYPE_GET = 0x00000001;
public const int KSPROPERTY_TYPE_SET = 0x00000002;
public const int KSPROPERTY_TYPE_TOPOLOGY = 0x10000000;

public Boolean SetValue(DirectShowLib.IBaseFilter pMediaSource, Guid cameraGuid, int nodeId, int propId, int transData)
{
    HRESULT hRet;
    DirectN.IKsTopologyInfo ksTopology;
    Guid iid;
    IntPtr pUnk1;
    IntPtr ppv1;
    object unk;

    pUnk1 = Marshal.GetComInterfaceForObject(pMediaSource, typeof(DirectShowLib.IBaseFilter));
    iid = new Guid("720D4AC0-7533-11D0-A5D6-28DB04C10000");
    ksTopology = pMediaSource as DirectN.IKsTopologyInfo;
    ppv1 = Marshal.GetComInterfaceForObject(ksTopology, typeof(DirectN.IKsTopologyInfo));

    hRet = Marshal.QueryInterface(pUnk1, ref iid, out ppv1);
    if (hRet != 0)
        return false;

    iid = new Guid("00000000-0000-0000-C000-000000000046");

    hRet = ksTopology.CreateNodeInstance((uint)nodeId, iid, out unk);
    if (hRet != 0)
        return false;

    IKsControl ksCnt;
    IntPtr pUnk2;
    IntPtr ppv2;

    pUnk2 = GCHandle.ToIntPtr(GCHandle.Alloc(unk));
    iid = new Guid("28F54685-06FD-11D2-B27A-00A0C9223196");
    ksCnt = unk as IKsControl;
    ppv2 = Marshal.GetComInterfaceForObject(ksCnt, typeof(IKsControl));

    hRet = Marshal.QueryInterface(pUnk2, ref iid, out ppv2);
    if (hRet != 0)
        return false;

    __struct_ks_2__union_0__struct_0 st;
    KSIDENTIFIER property;
    KSP_NODE prop;

    byte[] data = new byte[16];
    IntPtr propData = IntPtr.Zero;
    uint bytesReturned = 0;

    st.Set = cameraGuid;
    st.Id = (uint)propId;
    st.Flags = KSPROPERTY_TYPE_SET | KSPROPERTY_TYPE_TOPOLOGY;

    property = new KSIDENTIFIER();
    property.__union_0.__field_0 = st;

    prop = new KSP_NODE();
    prop.Property = property;
    prop.NodeId = (uint)nodeId;

    data[0] = (byte)(transData & 0xff);
    data[1] = 0;
    propData = Marshal.AllocHGlobal(data.Length);
    Marshal.Copy(data, 0, propData, data.Length);
    hRet = ksCnt.KsProperty(ref prop.Property, (uint)Marshal.SizeOf(prop), out propData, 1, out bytesReturned);

    Marshal.FreeHGlobal(propData);
 
    Marshal.FreeHGlobal(pUnk2);
    Marshal.FreeHGlobal(ppv2);
    Marshal.FreeHGlobal(pUnk1);
    Marshal.FreeHGlobal(ppv1);
 
    if (hRet != 0)
        return false;

    return true;
}

C#でIKsTopologyInfo, IKsControlを使用し、UVCカメラのCOM API取得する

現在C#および.NET FrameworkでUVCカメラのCOM API取得したいと考えております。

C++では下記リンクを参考にDirectShowのIKsTopologyInfoIKsControlインターフェイスを使用し、COM API取得することができました。

int SetValue(IBaseFilter * pMediaSource, int nodeId)
{
    HRESULT hRet;
    IKsTopologyInfo* ksTopology;
    IUnknown* unk;
    IKsControl* ksCnt;

    hRet = pMediaSource->QueryInterface(__uuidof(IKsTopologyInfo), (void**)&ksTopology);
    if (FAILED(hRet))
        return FALSE;

    hRet = ksTopology->CreateNodeInstance(nodeId, __uuidof(IUnknown), (VOID**)&unk);
    if (FAILED(hRet))
        return FALSE;

    hRet = unk->QueryInterface(__uuidof(IKsControl), (VOID**)&ksCnt);
    if (FAILED(hRet))
        return FALSE;

    return TRUE;
}
public Boolean SetValue(DirectShowLib.IBaseFilter pMediaSource, int nodeId)
{
    HRESULT hRet;
    DirectN.IKsTopologyInfo ksTopology;
    Guid iid;
    IntPtr pUnk1;
    IntPtr ppv1;
    object unk;

    pUnk1 = Marshal.GetComInterfaceForObject(pMediaSource, typeof(DirectShowLib.IBaseFilter));
    iid = new Guid("720D4AC0-7533-11D0-A5D6-28DB04C10000");
    ksTopology = pMediaSource as DirectN.IKsTopologyInfo;
    ppv1 = Marshal.GetComInterfaceForObject(ksTopology, typeof(DirectN.IKsTopologyInfo));

    hRet = Marshal.QueryInterface(pUnk1, ref iid, out ppv1);
    if (hRet != 0)
        return false;

    iid = new Guid("00000000-0000-0000-C000-000000000046");

    hRet = ksTopology.CreateNodeInstance((uint)nodeId, iid, out unk);
    if (hRet != 0)
        return false;

    IKsControl ksCnt;
    IntPtr pUnk2;
    IntPtr ppv2;

    pUnk2 = GCHandle.ToIntPtr(GCHandle.Alloc(unk));
    iid = new Guid("28F54685-06FD-11D2-B27A-00A0C9223196");
    ksCnt = unk as IKsControl;
    ppv2 = Marshal.GetComInterfaceForObject(ksCnt, typeof(IKsControl));

    hRet = Marshal.QueryInterface(pUnk2, ref iid, out ppv2);
    if (hRet != 0)
        return false;

    Marshal.FreeHGlobal(ppv2);
    Marshal.FreeHGlobal(pUnk2);
    Marshal.ReleaseComObject(ksCnt); 

    Marshal.FreeHGlobal(ppv1);
    Marshal.FreeHGlobal(pUnk1);
    Marshal.ReleaseComObject(ksTopology);

    return true;
}
関連する質問の記述変更
ソース リンク
user60510
user60510
読み込んでいます
本文から 9 文字削除
ソース リンク
cubick
  • 2.1万
  • 5
  • 27
  • 64
読み込んでいます
以前質問を行ったとリンクと、その旨の追加
ソース リンク
user60510
user60510
読み込んでいます
本文に 199 文字追加
ソース リンク
user60510
user60510
読み込んでいます
スペルミスおよび表記揺れの修正。タグを追加。
ソース リンク
読み込んでいます
本文に 12 文字追加
ソース リンク
cubick
  • 2.1万
  • 5
  • 27
  • 64
読み込んでいます
ソース リンク
user60510
user60510
読み込んでいます