VirtualBox

Changeset 45956 in vbox


Ignore:
Timestamp:
May 8, 2013 7:46:49 PM (12 years ago)
Author:
vboxsync
Message:

Main/VPX: multi-monitor fixes; use .webm as default extension

Location:
trunk/src/VBox/Main/src-client
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/DisplayImpl.cpp

    r45950 r45956  
    4949
    5050#ifdef VBOX_WITH_VPX
     51# include <iprt/path.h>
    5152# include "VideoRec.h"
    5253#endif
     
    528529
    529530#ifdef VBOX_WITH_VPX
    530     if (mpVideoRecCtx)
    531         VideoRecContextClose(mpVideoRecCtx);
     531    VideoRecContextClose(mpVideoRecCtx);
    532532#endif
    533533}
     
    33183318                                              pDrv->IConnector.cy, pDrv->IConnector.pu8Data, u64Now);
    33193319                }
    3320                 if (rc == VERR_TRY_AGAIN)
     3320                if (rc == VINF_TRY_AGAIN)
    33213321                    break;
    33223322            }
     
    43794379        for (unsigned uScreen = 0; uScreen < pDisplay->mcMonitors; uScreen++)
    43804380        {
     4381            char *pszAbsPath = RTPathAbsDup(com::Utf8Str(strFile).c_str());
     4382            char *pszExt = RTPathExt(pszAbsPath);
     4383            if (pszExt)
     4384                pszExt = RTStrDup(pszExt);
     4385            RTPathStripExt(pszAbsPath);
     4386            if (!pszAbsPath)
     4387                rc = VERR_INVALID_PARAMETER;
     4388            if (!pszExt)
     4389                pszExt = RTStrDup(".webm");
    43814390            char *pszName = NULL;
    4382             rc = RTStrAPrintf(&pszName, "%s-%u", com::Utf8Str(strFile).c_str(), uScreen);
     4391            if (RT_SUCCESS(rc))
     4392            {
     4393                if (pDisplay->mcMonitors > 1)
     4394                    rc = RTStrAPrintf(&pszName, "%s-%u%s", pszAbsPath, uScreen, pszExt);
     4395                else
     4396                    rc = RTStrAPrintf(&pszName, "%s%s", pszAbsPath, pszExt);
     4397            }
    43834398            if (RT_SUCCESS(rc))
    43844399                rc = VideoRecStrmInit(pDisplay->mpVideoRecCtx, uScreen,
     
    43894404            else
    43904405                LogRel(("Failed to initialize video recording context #%u (%Rrc)!\n", uScreen, rc));
    4391             if (pszName)
    4392                 RTStrFree(pszName);
     4406            RTStrFree(pszName);
     4407            RTStrFree(pszExt);
     4408            RTStrFree(pszAbsPath);
    43934409        }
    43944410    }
  • trunk/src/VBox/Main/src-client/VideoRec.cpp

    r45950 r45956  
    7878    /* true if video recording is enabled */
    7979    bool                fEnabled;
    80     /* worker thread */
    81     RTTHREAD            Thread;
    82     /* see VIDREC_xxx */
    83     uint32_t            u32State;
    8480    /* true if the RGB buffer is filled */
    8581    bool                fRgbFilled;
     
    10399    RTTHREAD            Thread;
    104100    /* see VIDREC_xxx */
    105     uint32_t            u32State;
     101    uint32_t            uState;
    106102    /* number of stream contexts */
    107103    uint32_t            cScreens;
     
    383379 * RGB/YUV conversion and encoding.
    384380 */
    385 DECLCALLBACK(int) videoRecThread(RTTHREAD ThreadSelf, void *pvUser)
     381static DECLCALLBACK(int) videoRecThread(RTTHREAD Thread, void *pvUser)
    386382{
    387383    PVIDEORECCONTEXT pCtx = (PVIDEORECCONTEXT)pvUser;
     
    391387        AssertRCBreak(rc);
    392388
    393         if (ASMAtomicReadU32(&pCtx->u32State) == VIDREC_TERMINATING)
     389        if (ASMAtomicReadU32(&pCtx->uState) == VIDREC_TERMINATING)
    394390            break;
    395391        for (unsigned uScreen = 0; uScreen < pCtx->cScreens; uScreen++)
     
    403399                    rc = videoRecEncodeAndWrite(pStrm);
    404400                if (RT_FAILURE(rc))
    405                     LogRel(("Error %Rrc encoding video frame\n", rc));
     401                {
     402                    static unsigned cErrors = 100;
     403                    if (cErrors > 0)
     404                    {
     405                        LogRel(("Error %Rrc encoding / writing video frame\n", rc));
     406                        cErrors--;
     407                    }
     408                }
    406409            }
    407410        }
    408411    }
    409412
    410     ASMAtomicWriteU32(&pCtx->u32State, VIDREC_TERMINATED);
    411     RTThreadUserSignal(ThreadSelf);
     413    ASMAtomicWriteU32(&pCtx->uState, VIDREC_TERMINATED);
    412414    return VINF_SUCCESS;
    413415}
     
    429431    for (unsigned uScreen = 0; uScreen < cScreens; uScreen++)
    430432        pCtx->Strm[uScreen].Ebml.last_pts_ms = -1;
    431    
     433
    432434    int rc = RTSemEventCreate(&pCtx->WaitEvent);
    433435    AssertRCReturn(rc, rc);
    434436
    435437    rc = RTThreadCreate(&pCtx->Thread, videoRecThread, (void*)pCtx, 0,
    436                         RTTHREADTYPE_MAIN_WORKER, 0, "VideoRec");
     438                        RTTHREADTYPE_MAIN_WORKER, RTTHREADFLAGS_WAITABLE, "VideoRec");
    437439    AssertRCReturn(rc, rc);
    438440
     441    ASMAtomicWriteU32(&pCtx->uState, VIDREC_INITIALIZED);
    439442    return VINF_SUCCESS;
    440443}
     
    466469    if (RT_FAILURE(rc))
    467470    {
    468         LogFlow(("Failed to open the output File\n"));
     471        LogFlow(("Failed to open the video capture output File (%Rrc)\n", rc));
    469472        return rc;
    470473    }
     
    474477    {
    475478        LogFlow(("Failed to configure codec\n", vpx_codec_err_to_string(rcv)));
    476         return rc;
     479        return VERR_INVALID_PARAMETER;
    477480    }
    478481
     
    490493    pStrm->uDelay = 1000 / uFps;
    491494
    492     struct vpx_rational arg_framerate = {30, 1};
     495    struct vpx_rational arg_framerate = { 30, 1 };
    493496    rc = Ebml_WriteWebMFileHeader(&pStrm->Ebml, &pStrm->VpxConfig, &arg_framerate);
    494497    AssertRCReturn(rc, rc);
     
    498501    if (rcv != VPX_CODEC_OK)
    499502    {
    500         LogFlow(("Failed to initialize encoder %s", vpx_codec_err_to_string(rcv)));
    501         return VERR_GENERAL_FAILURE;
    502     }
    503 
    504     ASMAtomicWriteU32(&pStrm->u32State, VIDREC_INITIALIZED);
     503        LogFlow(("Failed to initialize VP8 encoder %s", vpx_codec_err_to_string(rcv)));
     504        return VERR_INVALID_PARAMETER;
     505    }
    505506
    506507    if (!vpx_img_alloc(&pStrm->VpxRawImage, VPX_IMG_FMT_I420, uWidth, uHeight, 1))
     
    522523void VideoRecContextClose(PVIDEORECCONTEXT pCtx)
    523524{
    524     if (ASMAtomicReadU32(&pCtx->u32State) == VIDREC_UNINITIALIZED)
     525    if (!pCtx)
    525526        return;
    526527
    527     if (pCtx->fEnabled)
    528     {
    529         ASMAtomicWriteU32(&pCtx->u32State, VIDREC_TERMINATING);
    530         RTSemEventSignal(pCtx->WaitEvent);
    531         RTThreadUserWait(pCtx->Thread, 10000);
    532         RTSemEventDestroy(pCtx->WaitEvent);
    533     }
     528    if (ASMAtomicReadU32(&pCtx->uState) != VIDREC_INITIALIZED)
     529        return;
     530
     531    ASMAtomicWriteU32(&pCtx->uState, VIDREC_TERMINATING);
     532    RTSemEventSignal(pCtx->WaitEvent);
     533    RTThreadWait(pCtx->Thread, 10000, NULL);
     534    RTSemEventDestroy(pCtx->WaitEvent);
    534535
    535536    for (unsigned uScreen = 0; uScreen < pCtx->cScreens; uScreen++)
     
    549550        }
    550551        vpx_img_free(&pStrm->VpxRawImage);
    551         vpx_codec_destroy(&pStrm->VpxCodec);
     552        vpx_codec_err_t rcv = vpx_codec_destroy(&pStrm->VpxCodec);
     553        Assert(rcv == VPX_CODEC_OK);
    552554        RTMemFree(pStrm->pu8RgbBuf);
    553555        pStrm->pu8RgbBuf = NULL;
    554556    }
     557
     558    ASMAtomicWriteU32(&pCtx->uState, VIDREC_UNINITIALIZED);
    555559}
    556560
     
    682686    AssertReturn(uSourceHeight, VERR_INVALID_PARAMETER);
    683687    AssertReturn(uScreen < pCtx->cScreens, VERR_INVALID_PARAMETER);
     688    AssertReturn(pCtx->uState == VIDREC_INITIALIZED, VERR_INVALID_STATE);
    684689
    685690    PVIDEORECSTREAM pStrm = &pCtx->Strm[uScreen];
    686691
    687692    if (u64TimeStamp < pStrm->u64LastTimeStamp + pStrm->uDelay)
    688         return VINF_TRY_AGAIN;
     693        return VINF_TRY_AGAIN; /* respect maximum frames per second */
     694
     695    if (ASMAtomicReadBool(&pStrm->fRgbFilled))
     696        return VERR_TRY_AGAIN; /* previous frame not yet encoded */
     697
    689698    pStrm->u64LastTimeStamp = u64TimeStamp;
    690 
    691     if (ASMAtomicReadBool(&pStrm->fRgbFilled))
    692         return VERR_TRY_AGAIN;
    693699
    694700    int xDiff = ((int)pStrm->uTargetWidth - (int)uSourceWidth) / 2;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette