How to Configure the Proxy Locator

The application can change the default configuration of the proxy locator by setting the MFNETSOURCE_PROXYLOCATORFACTORY property to the proxy locator factory object that is implemented by the application. When the application calls source resolver methods to create the network source, Media Foundation calls the proxy locator factory. This object creates the proxy locator with custom configuration.

To change the default configuration setting of the proxy locator

  1. Implement the IMFNetProxyLocatorFactory interface.
  2. In the IMFNetProxyLocatorFactory::CreateProxyLocator method, do the following:
    1. Create a property store.
    2. Set the configuration settings for the proxy locator. For information about these settings, see Proxy Locator Configuration Settings.
    3. Call the MFCreateProxyLocator function. Pass in the property store and the protocol. The protocol is specified in the pszProtocol parameter of CreateProxyLocator.
  3. Create an instance of your proxy locator factory class and get a pointer to its IMFNetProxyLocatorFactory interface.
  4. Create another property store and set the value of the MFNETSOURCE_PROXYLOCATORFACTORY property equal to the IMFNetProxyLocatorFactory pointer from step 3.
  5. When you create the network source, pass the property store in the pProps parameter of the source resolver methods such as IMFSourceResolver::BeginCreateObjectFromURL.

Example

The following code example implements the IMFNetProxyLocatorFactory interface. The IMFNetProxyLocatorFactory::CreateProxyLocator method creates an instance of the default proxy locator, and configures it to operate in auto-detect mode.

class CProxyLocatorFactory : public IMFNetProxyLocatorFactory 
{
    LONG m_cRef;

public:

    CProxyLocatorFactory() : m_cRef(1)
    {
    }

    STDMETHODIMP QueryInterface(REFIID riid, void** ppv)
    {
        static const QITAB qit[] = 
        {
            QITABENT(CProxyLocatorFactory, IMFNetProxyLocatorFactory),
            { 0 }
        };
        return QISearch(this, qit, riid, ppv);
    }

    STDMETHODIMP_(ULONG) AddRef()
    {
        return InterlockedIncrement(&m_cRef);
    }

    STDMETHODIMP_(ULONG) Release()
    {
        LONG cRef = InterlockedDecrement(&m_cRef);
        if (cRef == 0)
        {
            delete this;
        }
        return cRef;
    }

    STDMETHODIMP CreateProxyLocator(
        LPCWSTR pszProtocol, 
        IMFNetProxyLocator **ppProxyLocator
        )
    {
        *ppProxyLocator = NULL;

        //Create the property store object
        IPropertyStore *pProp = NULL;

        HRESULT hr = PSCreateMemoryPropertyStore(IID_PPV_ARGS(&pProp));

        if(SUCCEEDED(hr))
        {
            // Property key for proxy settings.
            PROPERTYKEY key;
            key.fmtid = MFNETSOURCE_PROXYSETTINGS;        
            key.pid = 0;

            // Proxy settings
            PROPVARIANT var;
            var.vt = VT_I4;
            var.lVal = MFNET_PROXYSETTING_AUTO;

            hr = pProp->SetValue(key, var);
        }

        //Create the default proxy locator.

        if(SUCCEEDED(hr))
        {
            hr = MFCreateProxyLocator(pszProtocol, pProp, ppProxyLocator);
        }

        SafeRelease(&pProp);
        return hr;
    }
};

The next example shows how to pass the IMFNetProxyLocatorFactory pointer to the network source.

// Creates a media source from a URL.
//
// This example demonstrates how to set a proxy locator on the network source.

HRESULT CreateMediaSourceWithProxyLocator(
    PCWSTR pszURL, 
    IMFMediaSource **ppSource
    )
{
    IPropertyStore *pConfig = NULL;

    IMFNetProxyLocatorFactory *pFactory = new (std::nothrow) CProxyLocatorFactory();

    if (pFactory == NULL)
    {
        return E_OUTOFMEMORY;
    }

    // Configure the property store.
    HRESULT hr = PSCreateMemoryPropertyStore(IID_PPV_ARGS(&pConfig));

    if (SUCCEEDED(hr))
    {
        PROPERTYKEY key;
        key.fmtid =  MFNETSOURCE_PROXYLOCATORFACTORY;
        key.pid = 0;

        PROPVARIANT var;
        var.vt = VT_UNKNOWN;
        var.punkVal = pFactory;

        hr = pConfig->SetValue(key, var);
    }

    // Create the source media source.
    if (SUCCEEDED(hr))
    {
        hr = CreateMediaSource(pszURL, pConfig, ppSource);
    }

    SafeRelease(&pConfig);
    return hr;
}

Proxy Support for Network Sources