IWMEncDataViewCollection::Add
![]() |
The Add method adds an IWMEncDataView object to the collection.
Syntax
HRESULT Add(
IUnknown* pDataView,
long* plStreamCookie
);
Parameters
pDataView
[in] IUnknown pointer to an IWMEncDataView object.
plStreamCookie
[in, out] Pointer to a long containing the ID of the stream associated with the data view.
Return Values
If the method succeeds, it returns S_OK. If it fails, it supports an IErrorInfo interface and returns an HRESULT error code.
| Return code | Number | Description |
| E_FAIL | 0x80004005 | An error occurred. |
| E_INVALIDARG | 0x80070057 | A parameter is not valid. |
| E_OUTOFMEMORY | 0x8007000E | Memory cannot be allocated. |
| E_POINTER | 0x80004003 | The pointer to the data view object, or the pointer to the stream cookie, or both, are NULL. |
| NS_E_INVALIDCALL_WHILE_ENCODER_RUNNING | 0xC00D1B66 | This method cannot be called if the encoder engine is running. |
Remarks
Set plStreamCookie to -1 if the input stream is being associated with a data view object for the first time. The Add method produces a unique cookie for the stream. If plStreamCookie is not -1, the stream shares the preview or postview object with any stream whose ID is plStreamCookie.
Example Code
// Include libraries.
#include <windows.h>
#include <atlbase.h>
#include "wmencode.h"
#include "wmencvu.h"
// Declare variables.
HRESULT hr;
IWMEncoder* pEncoder;
IUnknown* pPreview;
IWMEncDataView* pPreview_1;
IWMEncDataView* pPreview_2;
IWMEncDataView* pPreview_3;
IWMEncDataViewCollection* pPreviewColl;
IWMEncSourceGroupCollection* pSrcGrpColl;
IWMEncSourceGroup* pSrcGrp;
IWMEncSource* pAudSrc;
IWMEncSource* pVidSrc;
long lCount, lCookie, i, lDataViewIndex;
// Initialize the COM library and retrieve a pointer
// to an IWMEncoder interface.
hr = CoInitialize(NULL);
if ( SUCCEEDED( hr ) )
{
hr = CoCreateInstance(CLSID_WMEncoder,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncoder,
(void**) &pEncoder);
}
// Retrieve a pointer to an IWMEncSourceGroupCollection
// interface.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);
}
// Add a source group to the collection.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp);
}
// Add a video and an audio source to the source group.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_VIDEO, &pVidSrc);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_AUDIO, &pAudSrc);
}
// Create three preview objects and return pointers.
if ( SUCCEEDED( hr ) )
{
hr = CoCreateInstance( CLSID_WMEncPreview,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncDataView,
(void**)&pPreview_1);
}
if ( SUCCEEDED( hr ) )
{
hr = CoCreateInstance( CLSID_WMEncPreview,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncDataView,
(void**)&pPreview_2);
}
if ( SUCCEEDED( hr ) )
{
hr = CoCreateInstance( CLSID_WMEncPreview,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncDataView,
(void**)&pPreview_3);
}
// Retrieve the preview collection.
if ( SUCCEEDED( hr ) )
{
hr = pVidSrc->get_PreviewCollection( &pPreviewColl );
}
// Add the preview objects to the data view collection. If you set the
// cookie to -1, the encoding process automatically generates a unique
// cookie.
long lCookie_1 = -1;
if ( SUCCEEDED( hr ) )
{
hr = pPreviewColl->Add( pPreview_1, &lCookie_1);
}
long lCookie_2 = -1;
if ( SUCCEEDED( hr ) )
{
hr = pPreviewColl->Add( pPreview_2, &lCookie_2);
}
long lCookie_3 = -1;
if ( SUCCEEDED( hr ) )
{
hr = pPreviewColl->Add( pPreview_3, &lCookie_3);
}
// Retrieve the cookies for each preview.
if ( SUCCEEDED( hr ) )
{
hr = pPreviewColl->get_Count(&lCount);
}
for (i=0; i<lCount; i++)
{
if ( SUCCEEDED( hr ) )
{
hr = pPreviewColl->Item(i, &pPreview, &lCookie);
}
}
// Remove the second preview object from the collection.
// The index is zero-based.
lDataViewIndex = 1;
if ( SUCCEEDED( hr ) )
{
hr = pPreviewColl->Remove(lDataViewIndex);
}
// Remove the remaining cookies from the collection.
if ( SUCCEEDED( hr ) )
{
hr = pPreviewColl->RemoveAll();
}
// Release pointers.
if ( pEncoder )
{
pEncoder->Release();
pEncoder = NULL;
}
if ( pPreview )
{
pPreview->Release();
pPreview = NULL;
}
if ( pPreviewColl )
{
pPreviewColl->Release();
pPreviewColl = NULL;
}
if ( pSrcGrpColl )
{
pSrcGrpColl->Release();
pSrcGrpColl = NULL;
}
if ( pSrcGrp )
{
pSrcGrp->Release();
pSrcGrp = NULL;
}
if ( pAudSrc )
{
pAudSrc->Release();
pAudSrc = NULL;
}
if ( pVidSrc )
{
pVidSrc->Release();
pVidSrc = NULL;
}
if ( pPreview_1 )
{
pPreview_1->Release();
pPreview_1 = NULL;
}
if ( pPreview_2 )
{
pPreview_2->Release();
pPreview_2 = NULL;
}
if ( pPreview_3 )
{
pPreview_3->Release();
pPreview_3 = NULL;
}
Requirements
Header: wmencvu.h
Library: wmprevu.dll
See Also
.gif)