Changeset 45956 in vbox
- Timestamp:
- May 8, 2013 7:46:49 PM (12 years ago)
- Location:
- trunk/src/VBox/Main/src-client
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-client/DisplayImpl.cpp
r45950 r45956 49 49 50 50 #ifdef VBOX_WITH_VPX 51 # include <iprt/path.h> 51 52 # include "VideoRec.h" 52 53 #endif … … 528 529 529 530 #ifdef VBOX_WITH_VPX 530 if (mpVideoRecCtx) 531 VideoRecContextClose(mpVideoRecCtx); 531 VideoRecContextClose(mpVideoRecCtx); 532 532 #endif 533 533 } … … 3318 3318 pDrv->IConnector.cy, pDrv->IConnector.pu8Data, u64Now); 3319 3319 } 3320 if (rc == V ERR_TRY_AGAIN)3320 if (rc == VINF_TRY_AGAIN) 3321 3321 break; 3322 3322 } … … 4379 4379 for (unsigned uScreen = 0; uScreen < pDisplay->mcMonitors; uScreen++) 4380 4380 { 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"); 4381 4390 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 } 4383 4398 if (RT_SUCCESS(rc)) 4384 4399 rc = VideoRecStrmInit(pDisplay->mpVideoRecCtx, uScreen, … … 4389 4404 else 4390 4405 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); 4393 4409 } 4394 4410 } -
trunk/src/VBox/Main/src-client/VideoRec.cpp
r45950 r45956 78 78 /* true if video recording is enabled */ 79 79 bool fEnabled; 80 /* worker thread */81 RTTHREAD Thread;82 /* see VIDREC_xxx */83 uint32_t u32State;84 80 /* true if the RGB buffer is filled */ 85 81 bool fRgbFilled; … … 103 99 RTTHREAD Thread; 104 100 /* see VIDREC_xxx */ 105 uint32_t u 32State;101 uint32_t uState; 106 102 /* number of stream contexts */ 107 103 uint32_t cScreens; … … 383 379 * RGB/YUV conversion and encoding. 384 380 */ 385 DECLCALLBACK(int) videoRecThread(RTTHREAD ThreadSelf, void *pvUser)381 static DECLCALLBACK(int) videoRecThread(RTTHREAD Thread, void *pvUser) 386 382 { 387 383 PVIDEORECCONTEXT pCtx = (PVIDEORECCONTEXT)pvUser; … … 391 387 AssertRCBreak(rc); 392 388 393 if (ASMAtomicReadU32(&pCtx->u 32State) == VIDREC_TERMINATING)389 if (ASMAtomicReadU32(&pCtx->uState) == VIDREC_TERMINATING) 394 390 break; 395 391 for (unsigned uScreen = 0; uScreen < pCtx->cScreens; uScreen++) … … 403 399 rc = videoRecEncodeAndWrite(pStrm); 404 400 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 } 406 409 } 407 410 } 408 411 } 409 412 410 ASMAtomicWriteU32(&pCtx->u32State, VIDREC_TERMINATED); 411 RTThreadUserSignal(ThreadSelf); 413 ASMAtomicWriteU32(&pCtx->uState, VIDREC_TERMINATED); 412 414 return VINF_SUCCESS; 413 415 } … … 429 431 for (unsigned uScreen = 0; uScreen < cScreens; uScreen++) 430 432 pCtx->Strm[uScreen].Ebml.last_pts_ms = -1; 431 433 432 434 int rc = RTSemEventCreate(&pCtx->WaitEvent); 433 435 AssertRCReturn(rc, rc); 434 436 435 437 rc = RTThreadCreate(&pCtx->Thread, videoRecThread, (void*)pCtx, 0, 436 RTTHREADTYPE_MAIN_WORKER, 0, "VideoRec");438 RTTHREADTYPE_MAIN_WORKER, RTTHREADFLAGS_WAITABLE, "VideoRec"); 437 439 AssertRCReturn(rc, rc); 438 440 441 ASMAtomicWriteU32(&pCtx->uState, VIDREC_INITIALIZED); 439 442 return VINF_SUCCESS; 440 443 } … … 466 469 if (RT_FAILURE(rc)) 467 470 { 468 LogFlow(("Failed to open the output File\n"));471 LogFlow(("Failed to open the video capture output File (%Rrc)\n", rc)); 469 472 return rc; 470 473 } … … 474 477 { 475 478 LogFlow(("Failed to configure codec\n", vpx_codec_err_to_string(rcv))); 476 return rc;479 return VERR_INVALID_PARAMETER; 477 480 } 478 481 … … 490 493 pStrm->uDelay = 1000 / uFps; 491 494 492 struct vpx_rational arg_framerate = { 30, 1};495 struct vpx_rational arg_framerate = { 30, 1 }; 493 496 rc = Ebml_WriteWebMFileHeader(&pStrm->Ebml, &pStrm->VpxConfig, &arg_framerate); 494 497 AssertRCReturn(rc, rc); … … 498 501 if (rcv != VPX_CODEC_OK) 499 502 { 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 } 505 506 506 507 if (!vpx_img_alloc(&pStrm->VpxRawImage, VPX_IMG_FMT_I420, uWidth, uHeight, 1)) … … 522 523 void VideoRecContextClose(PVIDEORECCONTEXT pCtx) 523 524 { 524 if ( ASMAtomicReadU32(&pCtx->u32State) == VIDREC_UNINITIALIZED)525 if (!pCtx) 525 526 return; 526 527 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); 534 535 535 536 for (unsigned uScreen = 0; uScreen < pCtx->cScreens; uScreen++) … … 549 550 } 550 551 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); 552 554 RTMemFree(pStrm->pu8RgbBuf); 553 555 pStrm->pu8RgbBuf = NULL; 554 556 } 557 558 ASMAtomicWriteU32(&pCtx->uState, VIDREC_UNINITIALIZED); 555 559 } 556 560 … … 682 686 AssertReturn(uSourceHeight, VERR_INVALID_PARAMETER); 683 687 AssertReturn(uScreen < pCtx->cScreens, VERR_INVALID_PARAMETER); 688 AssertReturn(pCtx->uState == VIDREC_INITIALIZED, VERR_INVALID_STATE); 684 689 685 690 PVIDEORECSTREAM pStrm = &pCtx->Strm[uScreen]; 686 691 687 692 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 689 698 pStrm->u64LastTimeStamp = u64TimeStamp; 690 691 if (ASMAtomicReadBool(&pStrm->fRgbFilled))692 return VERR_TRY_AGAIN;693 699 694 700 int xDiff = ((int)pStrm->uTargetWidth - (int)uSourceWidth) / 2;
Note:
See TracChangeset
for help on using the changeset viewer.