[74992] | 1 | /* $Id: RecordingInternals.cpp 99739 2023-05-11 01:01:08Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[75344] | 3 | * Recording internals code.
|
---|
[74992] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
[74992] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[74992] | 26 | */
|
---|
| 27 |
|
---|
[75344] | 28 | #include "RecordingInternals.h"
|
---|
[74992] | 29 |
|
---|
| 30 | #include <iprt/assert.h>
|
---|
| 31 | #include <iprt/mem.h>
|
---|
| 32 |
|
---|
[75346] | 33 | #ifdef VBOX_WITH_AUDIO_RECORDING
|
---|
[99739] | 34 |
|
---|
[74992] | 35 | /**
|
---|
[96481] | 36 | * Initializes a recording frame.
|
---|
| 37 | *
|
---|
| 38 | * @param pFrame Pointer to video frame to initialize.
|
---|
| 39 | * @param w Width (in pixel) of video frame.
|
---|
| 40 | * @param h Height (in pixel) of video frame.
|
---|
| 41 | * @param uBPP Bits per pixel (BPP).
|
---|
| 42 | * @param enmPixelFmt Pixel format to use.
|
---|
| 43 | */
|
---|
| 44 | int RecordingVideoFrameInit(PRECORDINGVIDEOFRAME pFrame, int w, int h, uint8_t uBPP, RECORDINGPIXELFMT enmPixelFmt)
|
---|
| 45 | {
|
---|
| 46 | /* Calculate bytes per pixel and set pixel format. */
|
---|
| 47 | const unsigned uBytesPerPixel = uBPP / 8;
|
---|
| 48 | const size_t cbRGBBuf = w * h * uBytesPerPixel;
|
---|
| 49 | AssertReturn(cbRGBBuf, VERR_INVALID_PARAMETER);
|
---|
| 50 |
|
---|
| 51 | pFrame->pu8RGBBuf = (uint8_t *)RTMemAlloc(cbRGBBuf);
|
---|
| 52 | AssertPtrReturn(pFrame->pu8RGBBuf, VERR_NO_MEMORY);
|
---|
| 53 | pFrame->cbRGBBuf = cbRGBBuf;
|
---|
| 54 |
|
---|
| 55 | pFrame->uX = 0;
|
---|
| 56 | pFrame->uY = 0;
|
---|
| 57 | pFrame->uWidth = w;
|
---|
| 58 | pFrame->uHeight = h;
|
---|
| 59 | pFrame->enmPixelFmt = enmPixelFmt;
|
---|
| 60 | pFrame->uBPP = uBPP;
|
---|
| 61 | pFrame->uBytesPerLine = w * uBytesPerPixel;
|
---|
| 62 |
|
---|
| 63 | return VINF_SUCCESS;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | /**
|
---|
| 67 | * Destroys a recording audio frame.
|
---|
| 68 | *
|
---|
| 69 | * @param pFrame Pointer to audio frame to destroy.
|
---|
| 70 | */
|
---|
| 71 | static void recordingAudioFrameDestroy(PRECORDINGAUDIOFRAME pFrame)
|
---|
| 72 | {
|
---|
| 73 | if (pFrame->pvBuf)
|
---|
| 74 | {
|
---|
| 75 | Assert(pFrame->cbBuf);
|
---|
| 76 | RTMemFree(pFrame->pvBuf);
|
---|
| 77 | pFrame->cbBuf = 0;
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | /**
|
---|
[75355] | 82 | * Frees a previously allocated recording audio frame.
|
---|
[74992] | 83 | *
|
---|
| 84 | * @param pFrame Audio frame to free. The pointer will be invalid after return.
|
---|
| 85 | */
|
---|
[75354] | 86 | void RecordingAudioFrameFree(PRECORDINGAUDIOFRAME pFrame)
|
---|
[74992] | 87 | {
|
---|
| 88 | if (!pFrame)
|
---|
| 89 | return;
|
---|
| 90 |
|
---|
[96481] | 91 | recordingAudioFrameDestroy(pFrame);
|
---|
| 92 |
|
---|
[74992] | 93 | RTMemFree(pFrame);
|
---|
| 94 | pFrame = NULL;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[99739] | 97 | #endif /* VBOX_WITH_AUDIO_RECORDING */
|
---|
| 98 |
|
---|
[74992] | 99 | /**
|
---|
[96481] | 100 | * Destroys a recording video frame.
|
---|
| 101 | *
|
---|
| 102 | * @param pFrame Pointer to video frame to destroy.
|
---|
| 103 | */
|
---|
| 104 | void RecordingVideoFrameDestroy(PRECORDINGVIDEOFRAME pFrame)
|
---|
| 105 | {
|
---|
| 106 | if (pFrame->pu8RGBBuf)
|
---|
| 107 | {
|
---|
| 108 | Assert(pFrame->cbRGBBuf);
|
---|
| 109 | RTMemFree(pFrame->pu8RGBBuf);
|
---|
| 110 | pFrame->cbRGBBuf = 0;
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | /**
|
---|
[75355] | 115 | * Frees a recording video frame.
|
---|
[74992] | 116 | *
|
---|
| 117 | * @param pFrame Pointer to video frame to free. The pointer will be invalid after return.
|
---|
| 118 | */
|
---|
[75354] | 119 | void RecordingVideoFrameFree(PRECORDINGVIDEOFRAME pFrame)
|
---|
[74992] | 120 | {
|
---|
| 121 | if (!pFrame)
|
---|
| 122 | return;
|
---|
| 123 |
|
---|
[96481] | 124 | RecordingVideoFrameDestroy(pFrame);
|
---|
| 125 |
|
---|
| 126 | RTMemFree(pFrame);
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | /**
|
---|
| 130 | * Frees a recording frame.
|
---|
| 131 | *
|
---|
| 132 | * @param pFrame Pointer to recording frame to free. The pointer will be invalid after return.
|
---|
| 133 | */
|
---|
| 134 | void RecordingFrameFree(PRECORDINGFRAME pFrame)
|
---|
| 135 | {
|
---|
| 136 | if (!pFrame)
|
---|
| 137 | return;
|
---|
| 138 |
|
---|
| 139 | switch (pFrame->enmType)
|
---|
[74992] | 140 | {
|
---|
[97404] | 141 | #ifdef VBOX_WITH_AUDIO_RECORDING
|
---|
[96481] | 142 | case RECORDINGFRAME_TYPE_AUDIO:
|
---|
| 143 | recordingAudioFrameDestroy(&pFrame->Audio);
|
---|
| 144 | break;
|
---|
[97404] | 145 | #endif
|
---|
[96481] | 146 | case RECORDINGFRAME_TYPE_VIDEO:
|
---|
| 147 | RecordingVideoFrameDestroy(&pFrame->Video);
|
---|
| 148 | break;
|
---|
| 149 |
|
---|
| 150 | default:
|
---|
| 151 | AssertFailed();
|
---|
| 152 | break;
|
---|
[74992] | 153 | }
|
---|
[96481] | 154 |
|
---|
[74992] | 155 | RTMemFree(pFrame);
|
---|
[96481] | 156 | pFrame = NULL;
|
---|
[74992] | 157 | }
|
---|
| 158 |
|
---|