Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
[La funzionalità associata a questa pagina, Windows Media Format 11 SDK, è una funzionalità legacy. È stata sostituita da Lettore di Origine e Scrittore Sink. Source Reader e Sink Writer sono stati ottimizzati per Windows 10 e Windows 11. Microsoft consiglia vivamente che il nuovo codice usi Source Reader e Sink Writer invece di Windows Media Format 11 SDK, quando possibile. Microsoft suggerisce che il codice esistente che usa le API legacy venga riscritto per usare le nuove API, se possibile.
Le interfacce delle informazioni sui codec usano tutti gli indici codec per identificare singoli codec. I codec vengono indicizzati in modo indipendente per l'audio e per il video. All'interno di un tipo di codec, gli indici vanno da 0 a uno minore del numero di codec di quel tipo.
Il codice di esempio seguente illustra come ottenere l'indice associato a ogni codec. Per compilare questo codice nell'applicazione, includere stdio.h.
HRESULT GetCodecNames(IWMCodecInfo3* pCodecInfo)
{
HRESULT hr = S_OK;
DWORD cCodecs = 0;
WCHAR* pwszCodecName = NULL;
DWORD cchCodecName = 0;
// Retrieve the number of supported audio codecs on the system.
hr = pCodecInfo->GetCodecInfoCount(WMMEDIATYPE_Audio, &cCodecs);
if(SUCCEEDED(hr))
printf("Number of audio codecs: %d\n\n", cCodecs);
else
{
printf("Could not get the count of audio codecs.\n");
return hr;
}
// Loop through all the audio codecs.
for(DWORD dwCodecIndex = 0; dwCodecIndex < cCodecs; dwCodecIndex++)
{
// Get the codec name:
// First, get the size of the name.
hr = pCodecInfo->GetCodecName(WMMEDIATYPE_Audio,
dwCodecIndex,
NULL,
&cchCodecName);
if(FAILED(hr))
{
printf("Could not get the size of the codec name.\n");
return hr;
}
// Allocate a string of the appropriate size.
pwszCodecName = new WCHAR[cchCodecName];
if(pwszCodecName == NULL)
{
printf("Could not allocate memory.\n");
return E_OUTOFMEMORY;
}
// Retrieve the codec name.
hr = pCodecInfo->GetCodecName(WMMEDIATYPE_Audio,
dwCodecIndex,
pwszCodecName,
&cchCodecName);
if(FAILED(hr))
{
delete[] pwszCodecName;
printf("Could not get the codec name.\n");
return hr;
}
// Print the codec name.
printf("%d %S\n", dwCodecIndex, pwszCodecName);
// Clean up for the next iteration.
delete[] pwszCodecName;
pwszCodecName = NULL;
cchCodecName = 0;
}
// Retrieve the number of supported video codecs on the system.
hr = pCodecInfo->GetCodecInfoCount(WMMEDIATYPE_Video, &cCodecs);
if(SUCCEEDED(hr))
printf("\n\nNumber of video codecs: %d.\n\n", cCodecs);
else
{
printf("Could not get the count of video codecs.\n");
return hr;
}
// Loop through all the video codecs.
for(dwCodecIndex = 0; dwCodecIndex < cCodecs; dwCodecIndex++)
{
// Get the codec name:
// First, get the size of the name.
hr = pCodecInfo->GetCodecName(WMMEDIATYPE_Video,
dwCodecIndex,
NULL,
&cchCodecName);
if(FAILED(hr))
{
printf("Could not get the size of the codec name.\n");
return hr;
}
// Allocate a string of the appropriate size.
pwszCodecName = new WCHAR[cchCodecName];
if(pwszCodecName == NULL)
{
printf("Could not allocate memory.\n");
return E_OUTOFMEMORY;
}
// Retrieve the codec name.
hr = pCodecInfo->GetCodecName(WMMEDIATYPE_Video,
dwCodecIndex,
pwszCodecName,
&cchCodecName);
if(FAILED(hr))
{
printf("Could not get the codec name.\n");
return hr;
}
// Print the codec name.
printf("%d %S\n", dwCodecIndex, pwszCodecName);
delete[] pwszCodecName;
pwszCodecName = NULL;
cchCodecName = 0;
}
return S_OK;
}
Argomenti correlati