Example #1
0
void CVideoControlSoft::OnPaint(wxPaintEvent& event)
{
#ifdef __WXGTK__
    double scale_factor = GetContentScaleFactor();
#else
    double scale_factor = 1.0f;
#endif
    GLTexture * glTexture = nullptr;
    //printf("OnPaint Soft Render begin \n"); 
#ifndef WIN32
    if(!renderBitmapOpenGL->IsInit())
    {
        renderBitmapOpenGL->Init(this);
        
    }
#endif
    
    std::clock_t start;
    start = std::clock();    
    

    int width = GetWindowWidth() * scale_factor;
    int height = GetWindowHeight() * scale_factor;
    if(width == 0 || height == 0)
        return;
	
	if (quitWindow)
        return;

#ifdef WIN32
    renderBitmapOpenGL->SetCurrent(*this);
#else
    if(updateContext)
    {
        renderBitmapOpenGL->SetCurrent(*this);
        updateContext = false;
    }   
#endif
    

    if (openCLEngine == nullptr)
    {
		openCLEngine = new COpenCLEngine();

		if (openCLEngine != nullptr)
			openclContext = openCLEngine->GetInstance();

		openclEffectYUV = new COpenCLEffectVideoYUV(openclContext);
    }

    nbFrame++;
    printf("Nb Frame per Seconds : %d \n",nbFrame);


    if (videoRenderStart && initStart)
    {
		//nbFrame = 0;
        if(!fpsTimer->IsRunning())
            fpsTimer->Start(1000);
	}

	if(videoRenderStart)
	{
        glTexture = RenderToGLTexture();
        if(glTexture != nullptr)
            printf("glTexture id : %d \n",glTexture->GetTextureID());
    }
    
    if(videoRenderStart && glTexture != nullptr)
    {       
        renderBitmapOpenGL->CreateScreenRender(width, height, CRgbaquad(0,0,0,0));

        if(glTexture != nullptr)
        {
            
            muVideoEffect.lock();
            int enableopenCL = videoEffectParameter.enableOpenCL;
            muVideoEffect.unlock();
            
            int inverted = 1;
            int x = (width - glTexture->GetWidth()) / 2;
            int y = (height  - glTexture->GetHeight()) / 2;
            if(openclContext->IsSharedContextCompatible())
                inverted = 0;
               
            if(!enableopenCL)
                inverted = 1;
                
            if(isffmpegDecode)
                inverted = 1;
                
            //printf("Inverted %d Enable OpenCL %d \n",inverted, enableopenCL);
            printf("flipH : %d flipV : %d inverted : %d \n", flipH, flipV, inverted);
            muVideoEffect.lock();
            renderBitmapOpenGL->RenderWithEffect(x,y, glTexture, &videoEffectParameter, flipH, flipV, inverted);
            printf("Rotation : %d \n",videoEffectParameter.rotation);
            muVideoEffect.unlock();
            
             
        }

        muVideoEffect.lock();
        if(videoEffectParameter.showFPS)
        {
            renderBitmapOpenGL->Print(0, 1, CConvertUtility::ConvertToUTF8(msgFrame));
        }
        muVideoEffect.unlock();

        muSubtitle.lock();

        if(subtilteUpdate && pictureSubtitle != nullptr)
        {
            renderBitmapOpenGL->SetSubtitle(pictureSubtitle);

            delete pictureSubtitle;
            pictureSubtitle = nullptr;

            subtilteUpdate = false;
        }
        else if(subtilteUpdate)
        {
            renderBitmapOpenGL->DeleteSubtitle();
            subtilteUpdate = false;
        }

        muSubtitle.unlock();

        if(videoEffectParameter.enableSubtitle)
        {
            renderBitmapOpenGL->ShowSubtitle();
        }    
	}
	else
	{
		renderBitmapOpenGL->CreateScreenRender(width, height, CRgbaquad(0,0,0,0));
	}

	this->SwapBuffers();

    if(deleteTexture && glTexture != nullptr)
        delete glTexture;
    

    double duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;


    std::cout<<"Video OnPaint Time : "<< duration <<'\n';
    

   // printf("OnPaint end \n");
}