Compartir a través de


DRM Support in QASF

 
Microsoft DirectShow 9.0

DRM Support in QASF

Reading and writing DRM-protected files in DirectShow is done in basically the same way as when you use the Windows Media Format SDK directly. To begin with, you need the wmstubdrm static library, which is obtained separately from Microsoft. In addition, you must implement the IKeyProvider interface to enable your application to access the Windows Media Format SDK run-time objects when DRM is enabled.

When applying DRM version 1 protection, use the IWMHeaderInfo interface, which is obtained as described in Reading ASF Files in DirectShow. When applying DRM version 7 protection, obtain the IWMDRMWriter interface by calling QueryService on the WM ASF Writer filter, as shown in the code snippet later in this topic.

Building Filter Graphs in DRM-Enabled Applications

If your application supports playback of DRM-protected files, then you generally should not use RenderFile to create the filter graph because there is no way to specify which DRM rights you are requesting before the file is opened. The WM ASF Reader by default asks for only playback rights. The filter is not added to the graph, and is therefore not discoverable by applications, until a file is successfully opened. 

To build a DRM-enabled playback graph using the WM ASF Reader, you must instantiate the filter using CoCreateInstance, add it to the filter graph using IFilterGraph::AddFilter, configure it, and then render its output pins. This technique is demonstrated in the PlayWndASF sample. When you build the graph in this way, you already have the IBaseFilter pointer that can be used to call QueryService to obtain IWMDRMWriter. However, this interface is not available until the Windows Media Format SDK reader object is created internally by the WM ASF Reader. The first opportunity the application has to set DRM rights is in its WMT_NO_RIGHTS_EX event handler, as shown in this code snippet:

case WMT_NO_RIGHTS_EX:

    IServiceProvider *pServiceProvider;
    IWMDRMReader pWMDRMReader;
    JIF(g_pReader->QueryInterface(IID_IServiceProvider, (void **) &pServiceProvider));
    JIF(pServiceProvider->QueryService(IID_IWMDRMReader, IID_IWMDRMReader, (void **) &pWMDRMReader)); 
    SAFE_RELEASE(pServiceProvider);

    // Set the rights we want for this file. These are the actions we 
    // might want to perform on the file. Here we ask for two rights only.
    // In a real application you should enable users to select which 
    // rights they want.
    hr = pWMDRMReader->SetDRMProperty(g_wszWMDRM_Rights, WMT_TYPE_STRING,
        BYTE*) wszRights, (sizeof(wszRights) / sizeof(wszRights[0])) * 2);
    SAFE_RELEASE(pWMDRMReader);
    if (FAILED(hr))
    {
       Msg(TEXT("SetDRMProperty Failed!  hr=0x%x\n"), hr);
       return hr;
    }
    // Now proceed with license acqusition.
    if( pEventData->pData )
    {
        hr = HandleNoRightsEx(pEventData->hrStatus, 
        (WM_GET_LICENSE_DATA *)pEventData->pData);
    }
    else
    {
         hr = E_FAIL;
    }
    break;

See Also