Platform SDK: TAPI

Acquiring a Multicast Address

The following code fragment illustrates how to request and set a multicast address for a conference.

For the sake of simplicity, this fragment shows the assignment of one multicast address to one media item. In actuality, the selection of a scope, the multicast address request, and the assignment will be performed for every media item involved in the conference.

This fragment assumes that connecting to an ILS server has already been performed. The operations shown here would be performed in the "Modify the settings if necessary" section of Creating a Conference Announcement.

// Get the Conference blob interface pointer 
// from the Directory object.
ITConferenceBlob * pConBlob;
hr = pDirectoryObject->QueryInterface(
        IID_ITConferenceBlob, 
        (void **) &pConBlob
        );

// Get the SDP blob interface pointer
// from conference blob.
ITSdp * pSdp;
hr = pConBlob->QueryInterface(
        IID_ITSdp, 
        (void **) &pSdp
        );

// Get the media collection associated with
// the SDP blob, and a count of the media.
ITMediaCollection *pMC;
hr = pSdp->get_MediaCollection(&pMC) 
long lMCCount = 0;
pMC->get_Count( &lMCCount );


// Create the multicast object.
IMcastAddressAllocation *pIMcastAddressAllocation;
HRESULT hr = CoCreateInstance(  
        CLSID_IMcastAddressAllocation,
        NULL,
        CLSCTX_INPROC_SERVER,
        IID_IMcastAddressAllocation,
        (void **) &pIMcastAddressAllocation
        );

// Get an enumeration of 
// multicast scopes available.
IEnumMcastScope *pEnum = NULL;
hr = pIMcastAddressAllocation->EnumerateScopes(&pEnum)) )

// Select a multicast scope.
IMcastScope *pScope;
hr = pEnum->Next(1, &pScope, NULL)

// Request an address.
// If successful, return the lease information.
DATE dateStart, dateStop;
SystemTimeToVariantTime( pStart, &dateStart );
SystemTimeToVariantTime( pStop, &dateStop );
IMcastLeaseInfo *pInfo;
hr = pIMcastAddressAllocation->RequestAddress( 
        pScope, 
        dateStart, 
        dateStop, 
        1, 
        &pInfo 
        );

// 
unsigned char nTTL = 15;
long lTemp;
hr = pInfo->get_TTL(&lTemp)
nTTL = (unsigned char) nTTL;

// Get a multicast address.
IEnumBstr *pEnumAddr = NULL;
hr = pInfo->EnumerateAddresses(
        &pEnumAddr)
BSTR bstrAddress = NULL;
hr = pEnumAddr->Next(1, &bstrAddress, NULL);

// Set the address using the ITConnection interface
// on the Media object.
ITMedia *pMedia;
hr = pMC->get_Item( 0, &pMedia);
ITConnection *pITConn;
hr = pMedia->QueryInterface(
        IID_ITConnection,
        (void **) &pITConn
        );
hr = pITConn->SetAddressInfo(
        bstrAddress,
        1,
        nTTL
        );

See Also

Multicast COM Interfaces, IMcastAddressAllocation, IMcastScope, IMcastLeaseInfo, IEnumMcastScope, ITConferenceBlob, ITSdp, ITMediaCollection, IEnumBstr, ITMedia, ITConnection