Menu

About the fuction---setFrameCallback

Help
ling bing
2010-08-03
2012-12-10
  • ling bing

    ling bing - 2010-08-03

    when I intializevideoman,I can call setFramecallback().
    Does it mean that it is not necessary to creat a new thread to play the video.
    what I should do is just define a CALLBACK function ,
    and then , when a new frame is available,it will call the CALLBACK automatically.
    In the CALLBACK function I will send a message to the mainwindow to tell him that it is time to renderframe now.
    And it will call ON_MESSAGE function in which I render the context.
    Is it right?Thank you.
    PS: I am trying to integrate VideoMan with MFC

     
  • Javier Barandiaran Martirena

    Yes you are right

     
  • ling bing

    ling bing - 2010-08-04

    void CVMControlDlg::callback(char* pixel)
    {
    char* image = pixel;
    PostMessage(hWnd,WM_NEWFRAME,0,(LPARAM)image);
    }

    I don't know how to transfer the HWND to this CALLBACK function.
    So I define a Global variables hWnd .
    when I initialize Dialog ,I make hWnd = m_hWnd.

    LRESULT CVMControlDlg::OnNewFrame(WPARAM wPARAM,LPARAM lPARAM)
    {
    char* image = (char*) lPARAM;

    inputContext.openGLDevice.makeCurrent();   //maybe it is wrong here?

    if ( image == NULL )
    return 0;
    image = NULL;
    //Clear the opengl window
    glClear( GL_COLOR_BUFFER_BIT );
    //Update the texture of the renderer
    videoMan.updateTexture( videoInputID );
    //Release the frame
    videoMan.releaseFrame( videoInputID );
    //render the image of input n in the screen
    videoMan.renderFrame( videoInputID );
                         SwapBuffers(inputContext.dc->m_hDC);
                         return 1;
    }

    I only get a blank screen….

     
  • Javier Barandiaran Martirena

    I think that the code is correct. You can check if the image in OnNewFrame is correct and if there is no other message that is invalidating your window. Also remember that the input must be initialized after the opengl context is created and is the current context.
    This is not needed inputContext.openGLDevice.makeCurrent if you don't have more opengl contexts

     
  • ling bing

    ling bing - 2010-08-04

    It happens a very strange error,

    for the first time I open a video file, I get a blank screen and the normal sound.
    Apprarently , it has been opened successfully but something goes wrong when render the frame.

    But if I click the open button and open a video file again,it shows me the frames.

    I don't know why.

    void CVMControlDlg::OnBnClickedOpen()
    {
    // TODO: Add your control notification handler code here
    if(m_fopen)
    {
    m_fopen = false;
    videoMan.stopVideo(videoInputID);//stop playing
    videoMan.deleteInput(videoInputID);//delete last video's information
    }//           I have no idea about this paragraph.

                        CString filter;
    filter = "视频文件(*.AVI)|*.AVI||";//过滤字符串
    CFileDialog fileDlg(true,NULL,NULL,OFN_HIDEREADONLY,filter);//打开文件对话框
    if(fileDlg.DoModal() == IDOK)
    {
    CString fileName;
    fileName = fileDlg.GetPathName();

                         USES_CONVERSION;   
                         char* videofile = NULL;   
    videofile = T2A(fileName.GetBuffer(fileName.GetLength()+1));
    if(intializeVideoman(videofile))
    m_fopen = true;
    }
    }

    bool CVMControlDlg::intializeVideoman(char* videoFile)
    {
    videoInputID = -1;
    if ( videoFile )
    {
    VideoManInputFormat format;
    inputIdentification device;
    //Initialize one input from a video file
    device.fileName = videoFile;
    #ifdef WIN32
    device.identifier = "DSHOW_VIDEO_FILE"; //using directshow
    #elif linux
    device.identifier = "HIGHGUI_VIDEO_FILE"; //using highugui
    #endif
    //play in real-time
    format.clock = true;
    format.dropFrames = true;
    //Render the audio stream
    format.renderAudio = true;
    //Initialize the video file is the path
    if ( ( videoInputID = videoMan.addVideoInput( device, &format ) ) != -1 )
    {
    //get the length of the video
    videoLengthSeconds = videoMan.getLengthSeconds( videoInputID );
    videoLengthFrames = videoMan.getLengthFrames( videoInputID );
    int screenLeft = 0;
    int screenUp = 0;
    int screenWidth = inputRect.Width();
    int screenHeight = inputRect.Height();
    videoMan.changeScreenSize(screenLeft,screenUp,screenWidth,screenHeight);

                                                                    useCallback = videoMan.supportFrameCallback( videoInputID );
                                                                    if ( useCallback )
            videoMan.setFrameCallback( videoInputID, callback );
    videoMan.playVideo( videoInputID );
    }
    }
    videoMan.activateAllVideoInputs();
    return ( videoInputID != -1 );
    }

    thank you

     
  • Javier Barandiaran Martirena

    Did you call videoMan.changeScreenSize in your resize callback?

     
  • ling bing

    ling bing - 2010-08-04

    Nop because my dialog size can't change its size now.
    so,as you can see, I call videoMan.changeScreenSize() when I intialize videoman.

     
  • ling bing

    ling bing - 2010-08-05

    The problem doesn't exist now,I don't know why.
    But the most important thing is it works well.
    Maybe something happen to my software or some other libs.

     
  • ling bing

    ling bing - 2010-08-05

    Ohhhhhhhhhhhhhhh,NO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    it works well because I add this to the project.
    when I intialize the Dialog,I call this function.
    wglShareLists(inputContext.openGLDevice.renderContext,outputContext.openGLDevice.renderContext);

     
  • ling bing

    ling bing - 2010-08-05

    And about this problem.
    there is another strange thing happened.
    If I draw any graph on the render context (just for once) ,the context can work well.
    but if I draw on two context (each for once),the latter will work well ,and the previous only gives me a blank screen(actually, it is not all background color, I can see the background which is black but the render zone is white ).

     
  • ling bing

    ling bing - 2010-08-05

    you are right ,I find that I have to share it .
    the cause of the problem is I build two render context.

     
  • Alexander

    Alexander - 2011-05-05

    juliafzy, hello.

    I've spend a lot of time to solve the problem of blank screens, but have no result yet.

    Could you publish the solution source code?

     

Log in to post a comment.