Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Question about WM Encodor SDK (Read 2836 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Question about WM Encodor SDK

I am new to the Windows Media Encoder SDK and I am facing a strange problem.
I have successfully called put_AutoStop() and yet the encoder doesn't seem
to stop. I am just encoding a small PCM WAVE file to a WMA. The following is
my code. Can someone help me out?


Code: [Select]
void main()
{
   HRESULT hr;
   IWMEncoder* pEncoder;
   IWMEncSourceGroupCollection* pSrcGrpColl;
   IWMEncSourceGroup* pSrcGrp;
   IWMEncSource* pSrcAud;
   IWMEncFile* pFile;

   // Initialize the COM library
   hr = CoInitialize(NULL);

   // Retrieve a pointer to an IWMEncoder interface
   if (SUCCEEDED(hr))
   {
       hr = CoCreateInstance(CLSID_WMEncoder,
           NULL,
           CLSCTX_INPROC_SERVER,
           IID_IWMEncoder,
           (void**) &pEncoder);
   }

   // Set up the input
   if (SUCCEEDED(hr))
       hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);
   if (SUCCEEDED(hr))
       hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp);
   if (SUCCEEDED(hr))
       hr = pSrcGrp->AddSource(WMENC_AUDIO, &pSrcAud);
   if (SUCCEEDED(hr))
       hr = pSrcAud->SetInput(CComBSTR("c:\\test\\in.wav"));
   if (SUCCEEDED(hr))
       hr = pSrcGrp->put_Profile(CComVariant("c:\\test\\in.prx"));

   // Set up the output
   if (SUCCEEDED(hr))
       hr = pEncoder->get_File(&pFile);
   if (SUCCEEDED(hr))
       hr = pFile->put_LocalFileName(CComBSTR("c:\\test\\out.wma"));

   // Set auto-stop and start encoding
   if (SUCCEEDED(hr))
       hr = pEncoder->put_AutoStop(VARIANT_TRUE);
   if (SUCCEEDED(hr))
       hr = pEncoder->PrepareToEncode(VARIANT_TRUE);
   if (SUCCEEDED(hr))
       hr = pEncoder->Start();

   WMENC_ENCODER_STATE enumState = WMENC_ENCODER_RUNNING;

   // **  Infinite loop - the state never changes! **
   while (enumState == WMENC_ENCODER_RUNNING)
   {
       pEncoder->get_RunState(&enumState);
       printf("Current state %d.\n", enumState);
       Sleep(500);
   }

   // Stop the encoder manually
   pEncoder->Stop();

   // Release pointers.
   if (pSrcGrpColl)
   {
       pSrcGrpColl->Release();
       pSrcGrpColl = NULL;
   }
   if (pSrcGrp)
   {
       pSrcGrp->Release();
       pSrcGrp = NULL;
   }
   if (pFile)
   {
       pFile->Release();
       pFile = NULL;
   }
   if (pSrcAud)
   {
       pSrcAud->Release();
       pSrcAud = NULL;
   }
   if (pEncoder)
   {
       pEncoder->Release();
       pEncoder = NULL;
   }
}