VirtualBox

Changeset 48600 in vbox


Ignore:
Timestamp:
Sep 20, 2013 2:30:46 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
89166
Message:

VBoxManage,Main: IHost::VideoCaptureDevices. Windows host implementation.

Location:
trunk/src/VBox
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp

    r48538 r48600  
    733733
    734734/**
     735 * List video capture devices.
     736 *
     737 * @returns See produceList.
     738 * @param   pVirtualBox         Reference to the IVirtualBox pointer.
     739 */
     740static HRESULT listVideoCaptureDevices(const ComPtr<IVirtualBox> pVirtualBox)
     741{
     742    HRESULT rc;
     743    ComPtr<IHost> host;
     744    CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
     745    com::SafeIfaceArray<IHostVideoCaptureDevice> hostVideoCaptureDevices;
     746    CHECK_ERROR(host, COMGETTER(VideoCaptureDevices)(ComSafeArrayAsOutParam(hostVideoCaptureDevices)));
     747    RTPrintf("Video Capture Devices: %u\n", hostVideoCaptureDevices.size());
     748    for (size_t i = 0; i < hostVideoCaptureDevices.size(); ++i)
     749    {
     750        ComPtr<IHostVideoCaptureDevice> p = hostVideoCaptureDevices[i];
     751        Bstr name;
     752        p->COMGETTER(Name)(name.asOutParam());
     753        Bstr path;
     754        p->COMGETTER(Path)(path.asOutParam());
     755        Bstr alias;
     756        p->COMGETTER(Alias)(alias.asOutParam());
     757        RTPrintf("%ls \"%ls\"\n%ls\n", alias.raw(), name.raw(), path.raw());
     758    }
     759    return rc;
     760}
     761
     762
     763/**
    735764 * The type of lists we can produce.
    736765 */
     
    760789    kListExtPacks,
    761790    kListGroups,
    762     kListNatNetworks
     791    kListNatNetworks,
     792    kListVideoCaptureDevices
    763793};
    764794
     
    10941124        }
    10951125
     1126        case kListVideoCaptureDevices:
     1127            rc = listVideoCaptureDevices(pVirtualBox);
     1128            break;
     1129
    10961130        /* No default here, want gcc warnings. */
    10971131
     
    11421176        { "extpacks",           kListExtPacks,           RTGETOPT_REQ_NOTHING },
    11431177        { "groups",             kListGroups,             RTGETOPT_REQ_NOTHING },
     1178        { "webcams",            kListVideoCaptureDevices, RTGETOPT_REQ_NOTHING },
    11441179    };
    11451180
     
    11871222            case kListGroups:
    11881223            case kListNatNetworks:
     1224            case kListVideoCaptureDevices:
    11891225                enmOptCommand = (enum enmListType)ch;
    11901226                if (fOptMultiple)
  • trunk/src/VBox/Main/Makefile.kmk

    r48578 r48600  
    304304        $(PATH_STAGE_LIB)/SSMStandalone$(VBOX_SUFF_LIB) \
    305305        $(LIB_DDU)
     306VBoxSVC_LIBS.win += strmiids.lib
    306307VBoxSVC_SDKS = VBOX_LIBPNG VBOX_ZLIB
    307308VBoxSVC_LIBS.solaris = \
  • trunk/src/VBox/Main/include/HostVideoCaptureDeviceImpl.h

    r48589 r48600  
    4040
    4141    /* Public initializer/uninitializer for internal purposes only. */
    42     HRESULT init(com::Utf8Str name, com::Utf8Str path, com::Utf8Str alias);
     42    HRESULT init(const com::Utf8Str &name, const com::Utf8Str &path, const com::Utf8Str &alias);
    4343    void uninit();
    4444
  • trunk/src/VBox/Main/src-server/HostVideoCaptureDeviceImpl.cpp

    r48578 r48600  
    2020#include "Logging.h"
    2121
     22#ifdef RT_OS_WINDOWS
     23#include <dshow.h>
     24#endif
     25
    2226/*
    2327 * HostVideoCaptureDevice implementation.
     
    4044 * Initializes the instance.
    4145 */
    42 HRESULT HostVideoCaptureDevice::init(com::Utf8Str name, com::Utf8Str path, com::Utf8Str alias)
     46HRESULT HostVideoCaptureDevice::init(const com::Utf8Str &name, const com::Utf8Str &path, const com::Utf8Str &alias)
    4347{
    4448    LogFlowThisFunc(("\n"));
     
    7680}
    7781
     82static HRESULT hostVideoCaptureDeviceAdd(HostVideoCaptureDeviceList *pList,
     83                                         const com::Utf8Str &name,
     84                                         const com::Utf8Str &path,
     85                                         const com::Utf8Str &alias)
     86{
     87    ComObjPtr<HostVideoCaptureDevice> obj;
     88    HRESULT hr = obj.createObject();
     89    if (SUCCEEDED(hr))
     90    {
     91        hr = obj->init(name, path, alias);
     92        if (SUCCEEDED(hr))
     93            pList->push_back(obj);
     94    }
     95    return hr;
     96}
     97
     98#ifdef RT_OS_WINDOWS
     99static HRESULT hvcdCreateEnumerator(IEnumMoniker **ppEnumMoniker)
     100{
     101    ICreateDevEnum *pCreateDevEnum = NULL;
     102    HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
     103                                  IID_PPV_ARGS(&pCreateDevEnum));
     104    if (SUCCEEDED(hr))
     105    {
     106        hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, ppEnumMoniker, 0);
     107        pCreateDevEnum->Release();
     108    }
     109    return hr;
     110}
     111
     112static HRESULT hvcdFillList(HostVideoCaptureDeviceList *pList, IEnumMoniker *pEnumMoniker)
     113{
     114    int iDevice = 0;
     115    IMoniker *pMoniker = NULL;
     116    while (pEnumMoniker->Next(1, &pMoniker, NULL) == S_OK)
     117    {
     118        IPropertyBag *pPropBag = NULL;
     119        HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
     120        if (FAILED(hr))
     121        {
     122            pMoniker->Release();
     123            continue;
     124        }
     125
     126        VARIANT var;
     127        VariantInit(&var);
     128
     129        hr = pPropBag->Read(L"DevicePath", &var, 0);
     130        if (FAILED(hr))
     131        {
     132            /* Can't use a device without path. */
     133            pMoniker->Release();
     134            continue;
     135        }
     136
     137        ++iDevice;
     138
     139        com::Utf8Str path = var.bstrVal;
     140        VariantClear(&var);
     141
     142        hr = pPropBag->Read(L"FriendlyName", &var, 0);
     143        if (FAILED(hr))
     144        {
     145            hr = pPropBag->Read(L"Description", &var, 0);
     146        }
     147
     148        com::Utf8Str name;
     149        if (SUCCEEDED(hr))
     150        {
     151            name = var.bstrVal;
     152            VariantClear(&var);
     153        }
     154        else
     155        {
     156            name = com::Utf8StrFmt("Video Input Device #%d", iDevice);
     157        }
     158
     159        com::Utf8Str alias = com::Utf8StrFmt(".%d", iDevice);
     160
     161        hr = hostVideoCaptureDeviceAdd(pList, name, path, alias);
     162
     163        pPropBag->Release();
     164        pMoniker->Release();
     165
     166        if (FAILED(hr))
     167            return hr;
     168    }
     169
     170    return S_OK;
     171}
     172
     173static HRESULT fillDeviceList(HostVideoCaptureDeviceList *pList)
     174{
     175    IEnumMoniker *pEnumMoniker = NULL;
     176    HRESULT hr = hvcdCreateEnumerator(&pEnumMoniker);
     177    if (SUCCEEDED(hr))
     178    {
     179        if (hr != S_FALSE)
     180        {
     181            /* List not empty */
     182            hr = hvcdFillList(pList, pEnumMoniker);
     183            pEnumMoniker->Release();
     184        }
     185        else
     186        {
     187            hr = S_OK; /* Return empty list. */
     188        }
     189    }
     190    return hr;
     191}
     192#else
     193static HRESULT fillDeviceList(HostVideoCaptureDeviceList *pList)
     194{
     195    NOREF(pList);
     196    return E_NOTIMPL;
     197}
     198#endif /* RT_OS_WINDOWS */
     199
    78200/* static */ HRESULT HostVideoCaptureDevice::queryHostDevices(HostVideoCaptureDeviceList *pList)
    79201{
    80     HRESULT hr = S_OK;
    81 #if 0
    82     PDARWINETHERNIC pEtherNICs = DarwinGetEthernetControllers();
    83     while (pEtherNICs)
    84     {
    85         ComObjPtr<HostNetworkInterface> IfObj;
    86         IfObj.createObject();
    87         if (SUCCEEDED(IfObj->init(Bstr(pEtherNICs->szName), Guid(pEtherNICs->Uuid), HostNetworkInterfaceType_Bridged)))
    88             list.push_back(IfObj);
    89 
    90         /* next, free current */
    91         void *pvFree = pEtherNICs;
    92         pEtherNICs = pEtherNICs->pNext;
    93         RTMemFree(pvFree);
    94     }
    95 #endif
     202    HRESULT hr = fillDeviceList(pList);
     203
     204    if (FAILED(hr))
     205    {
     206        pList->clear();
     207    }
     208
    96209    return hr;
    97210}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette