IWMSPlaylistParser::ReadPlaylist

banner art

Previous Next

IWMSPlaylistParser::ReadPlaylist

The ReadPlaylist method is called by the server to retrieve a playlist from an INSSBuffer object.

Syntax

  

Parameters

pBuffer

[in] Pointer to an INSSBuffer interface specifying the buffer to read from, in which the playlist file is loaded.

pPlaylist

[in] Pointer to an IXMLDOMDocument interface to be used to store the interpreted playlist that can be understood by the server.

pCallback

[in] Pointer to an IWMSPlaylistParserCallback interface that is used by the plug-in to report to the server the result of a call to the ReadPlaylist method.

qwContext

[in] QWORD containing a value defined by the server to identify which call to ReadPlaylist the plug-in is responding to when it calls IWMSPlaylistParserCallback::OnReadPlaylist. You must pass this value back unaltered when you call OnReadPlaylist.

Return Values

If the method succeeds, the plug-in must return S_OK. To report an error, the plug-in can return any HRESULT other than S_OK. If the plug-in uses the IWMSEventLog interface to log error information directly to the Windows Event Viewer, it is recommended that it return NS_E_PLUGIN_ERROR_REPORTED. Typically, the server attempts to make plug-in error information available to the server object model, the Windows Event Viewer, and the troubleshooting list in the details pane of the Windows Media Services MMC. However, if the plug-in uses the IWMSEventLog interface to send custom error information to the Windows Event Viewer, returning NS_E_PLUGIN_ERROR_REPORTED stops the server from also logging to the event viewer. For more information about retrieving plug-in error information, see Identifying Plug-in Errors.

Remarks

This method retrieves a playlist from an INSSBuffer object, parses it, and populates an IXMLDOMDocument object. This method is implemented by the plug-in and called by the server.

Example Code

HRESULT STDMETHODCALLTYPE 
CSDKSamplePlaylistParser::ReadPlaylist( 
                          INSSBuffer *pIBuffer,
                          IXMLDOMDocument *pPlayList,
                          IWMSPlaylistParserCallback *pCallback,
                          QWORD qwContext)
{
    HRESULT hr = S_OK;
    BYTE *pbBuffer = NULL;
    BYTE *pbEndBuffer = NULL;
    BYTE *pbUrl = NULL;
    BYTE *pbLineEnd = NULL;
    BYTE *pbEndUrl = NULL;

    DWORD dwLength = 0;
    BYTE bPrevious = '\0';
    BSTR bstrUrl = NULL;
    
    CComPtr<IXMLDOMNode> spWsxNode;
    CComPtr<IXMLDOMElement> spPlayListMediaEntry;
    CComPtr<IXMLDOMElement> spPlayListTopEntry;
    CComPtr<IXMLDOMNode> spOldPlayListEntry;

    BSTR bstrWsx = SysAllocString( L"wsx" );
    BSTR bstrEmpty = SysAllocString( L"" );
    BSTR bstrVersion = SysAllocString( L"version='1.0'" );
    BSTR bstrSmil = SysAllocString( L"smil" );
    BSTR bstrTagName = SysAllocString( L"media" );
    BSTR bstrAttrName = SysAllocString( L"src" );

    VARIANT varNodeType;
    VariantInit( &varNodeType );
    V_VT( &varNodeType ) = VT_I4;
    V_I4( &varNodeType ) = NODE_PROCESSING_INSTRUCTION;
    
    hr = pPlayList->createNode(
                        varNodeType,
                        bstrWsx,
                        bstrEmpty,
                        &spWsxNode
                        );
    
    VariantClear( &varNodeType );
    if ( FAILED(hr) ) goto EXIT;

    hr = pPlayList->appendChild( spWsxNode, &spOldPlayListEntry );
    if ( FAILED(hr) ) goto EXIT;

    hr = spWsxNode->put_text( bstrVersion );
    if ( FAILED(hr) ) goto EXIT;

    hr = pPlayList->createElement( bstrSmil, &spPlayListTopEntry );
    if ( FAILED(hr) ) goto EXIT;

    spOldPlayListEntry = NULL;
    hr = pPlayList->appendChild( spPlayListTopEntry,
                                 &spOldPlayListEntry );
    if ( FAILED(hr) ) goto EXIT;

    hr = pIBuffer->GetBufferAndLength( &pbBuffer, &dwLength );
    if ( FAILED( hr ) ) goto EXIT;

    pbEndBuffer = pbBuffer + dwLength;
    pbUrl = pbBuffer;

    while ( pbUrl < pbEndBuffer )
    {
        while( ( pbUrl < pbEndBuffer )
                && isspace( *pbUrl ) )
            ++pbUrl;

        if( pbUrl >= pbEndBuffer )
            break;

        pbLineEnd = pbUrl + 1;
        while( ( pbLineEnd < pbEndBuffer )
                && ( '\n' != *pbLineEnd )
                && ( '\r' != *pbLineEnd ) )
            ++pbLineEnd;

        if( '#' == *pbUrl )
        {
            pbUrl = pbLineEnd;
            continue;
        }

        pbEndUrl = pbLineEnd;

        while( ( pbUrl < pbEndUrl )
            && isspace( pbEndUrl[-1] ) )
            --pbEndUrl;

        if( ( pbUrl < pbEndUrl )
            && ( ',' == pbEndUrl[-1] ) )
            --pbEndUrl;

        while( ( pbUrl < pbEndUrl )
            && isspace( pbEndUrl[-1] ) )
            --pbEndUrl;

        if( pbUrl == pbEndUrl )
        {
            pbUrl = pbLineEnd;
            continue;
        }

        int cchNeeded = MultiByteToWideChar(
                                CP_ACP,
                                0,
                                (LPCSTR)pbUrl,
                                (int)( pbEndUrl - pbUrl ),
                                NULL,
                                0
                                );
        if( 0 >= cchNeeded )
        {
            hr = HRESULT_FROM_WIN32( GetLastError() );
            goto EXIT;
        }

        bstrUrl = SysAllocStringLen( NULL, cchNeeded );
        if( NULL == bstrUrl )
        {
            hr = E_OUTOFMEMORY;
            goto EXIT;
        }

        int cchConverted = MultiByteToWideChar(
                                    CP_ACP,
                                    0,
                                    (LPCSTR)pbUrl,
                                    (int)( pbEndUrl - pbUrl ),
                                    bstrUrl,
                                    cchNeeded
                                    );
        if( cchConverted != cchNeeded )
        {
            hr = HRESULT_FROM_WIN32( ERROR_NO_UNICODE_TRANSLATION );
            goto EXIT;
        }

        hr = pPlayList->createElement(
                            bstrTagName,
                            &spPlayListMediaEntry
                            );
        if ( FAILED( hr ) ) goto EXIT;

        VARIANT varAttribute;
        VariantInit( &varAttribute );
        V_VT( &varAttribute ) = VT_BSTR;
        V_BSTR( &varAttribute ) = bstrUrl;
        
        hr = spPlayListMediaEntry->setAttribute( bstrAttrName, varAttribute );

        V_BSTR( &varAttribute ) = NULL;
        V_VT( &varAttribute ) = VT_EMPTY;
        VariantClear( &varAttribute );

        if ( FAILED( hr ) ) goto EXIT;

        spOldPlayListEntry = NULL;
        hr = spPlayListTopEntry->appendChild( spPlayListMediaEntry, &spOldPlayListEntry );            
        if ( FAILED( hr ) ) goto EXIT;

        spPlayListMediaEntry.Release();

        pbUrl = pbLineEnd;
    }

    pCallback->OnReadPlaylist( S_OK, qwContext );

EXIT:
    // TODO: Release temporary COM objects and pointers.
    return( hr );
}

Requirements

Header: wmsplaylistparser.h.

Library: WMSServerTypeLib.dll.

Platform: Windows Server 2003, Enterprise Edition; Windows Server 2003, Datacenter Edition; Windows Server 2008.

See Also

Previous Next