VideoRec.cpp revision d01bb88591e2ae070aa233b99c81e58598d557e1
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Encodes the screen content in VPX format.
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Copyright (C) 2012-2013 Oracle Corporation
45e9809aff7304721fddb95654901b32195c9c7avboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
45e9809aff7304721fddb95654901b32195c9c7avboxsync * available from http://www.virtualbox.org. This file is free software;
45e9809aff7304721fddb95654901b32195c9c7avboxsync * you can redistribute it and/or modify it under the terms of the GNU
45e9809aff7304721fddb95654901b32195c9c7avboxsync * General Public License (GPL) as published by the Free Software
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
45e9809aff7304721fddb95654901b32195c9c7avboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
45e9809aff7304721fddb95654901b32195c9c7avboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
45e9809aff7304721fddb95654901b32195c9c7avboxsync/** Default VPX codec to use */
45e9809aff7304721fddb95654901b32195c9c7avboxsyncstatic int videoRecEncodeAndWrite(PVIDEORECSTREAM pStrm);
45e9809aff7304721fddb95654901b32195c9c7avboxsync/* state to synchronized between threads */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* initialized, idle */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* currently in VideoRecCopyToIntBuf(), delay termination */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* signal that we are terminating */
45e9809aff7304721fddb95654901b32195c9c7avboxsync/* Must be always accessible and therefore cannot be part of VIDEORECCONTEXT */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* container context */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* VPX codec context */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* VPX configuration */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* X resolution */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* Y resolution */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* X resolution of the last encoded picture */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* Y resolution of the last encoded picture */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* current frame number */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* RGB buffer containing the most recent frame of the framebuffer */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* YUV buffer the encode function fetches the frame from */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* VPX image context */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* true if video recording is enabled */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* true if the RGB buffer is filled */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* pixel format of the current frame */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* minimal delay between two frames */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* time stamp of the last frame we encoded */
typedef struct VIDEORECCONTEXT
bool fEnabled;
class ColorConvBGRA32Iter
mPos = 0;
bool rc = false;
rc = true;
return rc;
unsigned mSize;
unsigned mPos;
class ColorConvBGR24Iter
mPos = 0;
bool rc = false;
rc = true;
return rc;
unsigned mSize;
unsigned mPos;
class ColorConvBGR565Iter
mPos = 0;
bool rc = false;
rc = true;
return rc;
unsigned mSize;
unsigned mPos;
bool rc = true;
unsigned offY = 0;
if (rc)
if (rc)
if (rc)
if (rc)
++offU;
++offV;
if (rc)
return rc;
bool rc = true;
if (rc)
return rc;
if (cErrors > 0)
cErrors--;
return VINF_SUCCESS;
PVIDEORECCONTEXT pCtx = (PVIDEORECCONTEXT)RTMemAllocZ(RT_OFFSETOF(VIDEORECCONTEXT, Strm[cScreens]));
return VINF_SUCCESS;
return rc;
return VERR_INVALID_PARAMETER;
return VERR_INVALID_PARAMETER;
return VERR_NO_MEMORY;
return VINF_SUCCESS;
if (!pCtx)
return VERR_GENERAL_FAILURE;
if (!pkt)
case VPX_CODEC_CX_FRAME_PKT:
return rc;
case VPX_IMG_FMT_RGB32:
return VERR_GENERAL_FAILURE;
case VPX_IMG_FMT_RGB24:
return VERR_GENERAL_FAILURE;
case VPX_IMG_FMT_RGB565:
return VERR_GENERAL_FAILURE;
return VERR_GENERAL_FAILURE;
return VINF_SUCCESS;
return VINF_TRY_AGAIN;
if ((int)x < -xDiff)
w += xDiff + x;
x = -xDiff;
destX = 0;
if ((int)y < -yDiff)
h += yDiff + (int)y;
y = -yDiff;
destY = 0;
switch (uBitsPerPixel)
return rc;