Exemplo n.º 1
0
DWORD Renderer::RNDR_ThreadProc(LPVOID lpParam)
{
    DWORD           ret_val = 0;
    Renderer*       pThis = (Renderer*) lpParam;
    RNDR_StreamCode ret_code = RNDR_Abort;
    RndrCallback*   pCallBack = pThis->pCallBack;
    //length of the buffer should be no greater than total frames count
    unsigned long	uiBufLength = min(pThis->config.inbuff_len, unsigned long(pThis->ullSongFrameLength - pThis->ullCurrentFramePos));
    unsigned int    counter = 0;

    if (NULL != pCallBack)
    {
        while ((RNDR_STATUS_DATA_PROCESSING == pThis->state) &&
                (pThis->ullCurrentFramePos < pThis->ullSongFrameLength + 50) &&
               (RNDR_Continue == pCallBack(pThis->RENDER_BUFF, uiBufLength)))
        {
            /* Critical section start */
            pThis->AcquireSema();
            //ret_code = pCallBack(RENDER_BUFF, (sizeof(RENDER_BUFF)/sizeof(float)) / pThis->config.num_channels);
            sf_write_float(pThis->out_file, pThis->RENDER_BUFF, pThis->config.inbuff_len *2);
            ++counter;

            pThis->ullCurrentFramePos += uiBufLength;
            uiBufLength = min(uiBufLength, unsigned long(pThis->ullSongFrameLength - pThis->ullCurrentFramePos + 50));

            if (counter > 300)
            {
                sf_write_sync(pThis->out_file);
                counter = 0;
            }
            /* Critical section end */
            pThis->ReleaseSema();
        }
           // ExitThread(0);
           // pThis->RndrThread = 0;

        if ((counter < 300) && (counter > 0))
        {
            sf_write_sync(pThis->out_file);
        }

        pThis->AcquireSema();
        pThis->state = RNDR_STATUS_READY;
        pThis->ReleaseSema();
    }

    //ret_val = STILL_ACTIVE;

    return ret_val;
}