Quantcast
Channel: Media Foundation Development for Windows Desktop forum
Viewing all articles
Browse latest Browse all 1079

IMFTransform problem in decoding h.264

$
0
0

Help to see if there is any problem with the following code.   ppDecoder->processout returns no s_ok, and at last no video data got out.

IMFActivate **ppActivate = NULL;
UINT32 count = 0;
IMFTransform *ppDecoder;

GUID subtype = GUID_NULL;

      

       
hr = imfmediatype->GetGUID(MF_MT_SUBTYPE, &subtype);

    MFT_REGISTER_TYPE_INFO info = { 0 };
 MFT_REGISTER_TYPE_INFO info_2 = { 0 };
    info.guidMajorType = MFMediaType_Video;
    info.guidSubtype = subtype;

 info_2.guidMajorType = MFMediaType_Video;
    info_2.guidSubtype = MFVideoFormat_RGB32;
 
   hr = MFTEnumEx(
        MFT_CATEGORY_VIDEO_DECODER,
        MFT_ENUM_FLAG_SYNCMFT ,
        &info,      // Input type
        &info_2,       // Output type
        &ppActivate,
        &count
        );


    if (SUCCEEDED(hr) && count == 0)
    {
        return hr;
    }

   

    if (SUCCEEDED(hr))
    {
        hr = ppActivate[0]->ActivateObject(IID_PPV_ARGS(&ppDecoder));
    }

    for (UINT32 i = 0; i < count; i++)
    {
        ppActivate[i]->Release();
    }
   

hr = ppDecoder->SetInputType(0,imfmediatype,0);

IMFMediaType* pOutputType = NULL;  
 HRESULT hrRes = S_OK;

    GUID guidMajorType = GUID_NULL, guidSubType = GUID_NULL;
 
 
        for ( DWORD dwTypeIndex = 0; (hr != MF_E_NO_MORE_TYPES) ; dwTypeIndex++ )
        {
            hr =  ppDecoder->GetOutputAvailableType(
                                                0,
                                                dwTypeIndex,
                                               &pOutputType);

            if (pOutputType && SUCCEEDED(hr))
            {
                hr = pOutputType->GetMajorType( &guidMajorType );

                hr = pOutputType->GetGUID( MF_MT_SUBTYPE, &guidSubType );

              
           
                if((guidMajorType == MFMediaType_Video) && (guidSubType == MFVideoFormat_RGB32))
                {
                    hr =  ppDecoder->SetOutputType(0, pOutputType, 0);
                    break;
                } 

            }
            else
            {
                //Output type not found

                hr = E_FAIL;
                break;
            }
        }

hr = ppDecoder->ProcessMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING,NULL);
 
 hr = pSample->SetUINT32(MFSampleExtension_Discontinuity, TRUE);

 hr = ppDecoder->ProcessInput(0,pSample,0);

 MFT_OUTPUT_STREAM_INFO osi;

 hr = ppDecoder->GetOutputStreamInfo(0, &osi);

IMFMediaBuffer *pBuffer_test = NULL;

// hr = MFCreateMemoryBuffer(bytes , &pBuffer);
 hr = MFCreateMemoryBuffer(osi.cbSize, &pBuffer_test);

 pBuffer_test->SetCurrentLength(osi.cbSize);

IMFSample *outputSample=NULL;
 //hr = MFCreateVideoSampleFromSurface(NULL,&outputSample);
 hr = MFCreateSample(&outputSample);
 outputSample->AddBuffer(pBuffer_test);

 outputSample->AddRef();

 MFT_OUTPUT_DATA_BUFFER outputDataBuffer;
    ZeroMemory(&outputDataBuffer, sizeof(outputDataBuffer));
 
 DWORD processOutputStatus = 0;

 outputDataBuffer.dwStreamID = 0;
    outputDataBuffer.pSample = outputSample;
 //   outputDataBuffer.dwStatus = 0;
 //   outputDataBuffer.pEvents = NULL;


 hr = ppDecoder->GetOutputStatus(&m1);
 do
 {hr = ppDecoder->ProcessOutput(0,1,&outputDataBuffer,&processOutputStatus);
 }
 while(hr!= MF_E_TRANSFORM_NEED_MORE_INPUT);

 IMFSample* pBitmapSample = NULL;

 hr = MFCreateSample(&pBitmapSample);
 hr = pBitmapSample->AddBuffer(pBuffer_test);
 IMFMediaBuffer *buffer_test_2 =NULL;
 pBuffer_test->Release();
 pBuffer_test = NULL;
 //hr = pBitmapSample->ConvertToContiguousBuffer(&buffer_test_2);
    hr = outputDataBuffer.pSample->ConvertToContiguousBuffer(&buffer_test_2);

 BYTE *pData_test = NULL;
 DWORD cbTotalLength;
 DWORD cbCurrentLength;
 hr = buffer_test_2->Lock(&pData_test, &cbTotalLength, &cbCurrentLength);
 //hr = pBuffer_test->Lock(&pData_test, &cbTotalLength, &cbCurrentLength);
 IMFMediaType *pMediaType_test;
 hr =  ppDecoder->GetOutputCurrentType(0, &pMediaType_test);


 INT32 stride_test = 0;
 UINT32 m_Width;
 UINT32 m_Height;
 LONG stride_test_2=0;
    //Get the Frame size and stride through Media Type attributes

    hr = MFGetAttributeSize(pMediaType_test, MF_MT_FRAME_SIZE, &m_Width, &m_Height);

    hr = pMediaType_test->GetUINT32(MF_MT_DEFAULT_STRIDE, (UINT32*)&stride_test);

 hr = pMediaType_test->GetGUID(MF_MT_SUBTYPE, &subtype);

    hr = MFGetStrideForBitmapInfoHeader(subtype.Data1, m_Width, &stride_test_2);

 Bitmap* m_pBitmap;
    //Create the bitmap with the given size
    m_pBitmap = new Bitmap(m_Width, m_Height, (INT32)stride_test_2, PixelFormat32bppRGB, pData_test);


Viewing all articles
Browse latest Browse all 1079

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>