[74992] | 1 | /* $Id: RecordingInternals.cpp 98103 2023-01-17 14:15:46Z 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
|
---|
[74992] | 34 | /**
|
---|
[96481] | 35 | * Initializes a recording frame.
|
---|
| 36 | *
|
---|
| 37 | * @param pFrame Pointer to video frame to initialize.
|
---|
| 38 | * @param w Width (in pixel) of video frame.
|
---|
| 39 | * @param h Height (in pixel) of video frame.
|
---|
| 40 | * @param uBPP Bits per pixel (BPP).
|
---|
| 41 | * @param enmPixelFmt Pixel format to use.
|
---|
| 42 | */
|
---|
| 43 | int RecordingVideoFrameInit(PRECORDINGVIDEOFRAME pFrame, int w, int h, uint8_t uBPP, RECORDINGPIXELFMT enmPixelFmt)
|
---|
| 44 | {
|
---|
| 45 | /* Calculate bytes per pixel and set pixel format. */
|
---|
| 46 | const unsigned uBytesPerPixel = uBPP / 8;
|
---|
| 47 | const size_t cbRGBBuf = w * h * uBytesPerPixel;
|
---|
| 48 | AssertReturn(cbRGBBuf, VERR_INVALID_PARAMETER);
|
---|
| 49 |
|
---|
| 50 | pFrame->pu8RGBBuf = (uint8_t *)RTMemAlloc(cbRGBBuf);
|
---|
| 51 | AssertPtrReturn(pFrame->pu8RGBBuf, VERR_NO_MEMORY);
|
---|
| 52 | pFrame->cbRGBBuf = cbRGBBuf;
|
---|
| 53 |
|
---|
| 54 | pFrame->uX = 0;
|
---|
| 55 | pFrame->uY = 0;
|
---|
| 56 | pFrame->uWidth = w;
|
---|
| 57 | pFrame->uHeight = h;
|
---|
| 58 | pFrame->enmPixelFmt = enmPixelFmt;
|
---|
| 59 | pFrame->uBPP = uBPP;
|
---|
| 60 | pFrame->uBytesPerLine = w * uBytesPerPixel;
|
---|
| 61 |
|
---|
| 62 | return VINF_SUCCESS;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | /**
|
---|
| 66 | * Destroys a recording audio frame.
|
---|
| 67 | *
|
---|
| 68 | * @param pFrame Pointer to audio frame to destroy.
|
---|
| 69 | */
|
---|
| 70 | static void recordingAudioFrameDestroy(PRECORDINGAUDIOFRAME pFrame)
|
---|
| 71 | {
|
---|
| 72 | if (pFrame->pvBuf)
|
---|
| 73 | {
|
---|
| 74 | Assert(pFrame->cbBuf);
|
---|
| 75 | RTMemFree(pFrame->pvBuf);
|
---|
| 76 | pFrame->cbBuf = 0;
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | /**
|
---|
[75355] | 81 | * Frees a previously allocated recording audio frame.
|
---|
[74992] | 82 | *
|
---|
| 83 | * @param pFrame Audio frame to free. The pointer will be invalid after return.
|
---|
| 84 | */
|
---|
[75354] | 85 | void RecordingAudioFrameFree(PRECORDINGAUDIOFRAME pFrame)
|
---|
[74992] | 86 | {
|
---|
| 87 | if (!pFrame)
|
---|
| 88 | return;
|
---|
| 89 |
|
---|
[96481] | 90 | recordingAudioFrameDestroy(pFrame);
|
---|
| 91 |
|
---|
[74992] | 92 | RTMemFree(pFrame);
|
---|
| 93 | pFrame = NULL;
|
---|
| 94 | }
|
---|
| 95 | #endif
|
---|
| 96 |
|
---|
| 97 | /**
|
---|
[96481] | 98 | * Destroys a recording video frame.
|
---|
| 99 | *
|
---|
| 100 | * @param pFrame Pointer to video frame to destroy.
|
---|
| 101 | */
|
---|
| 102 | void RecordingVideoFrameDestroy(PRECORDINGVIDEOFRAME pFrame)
|
---|
| 103 | {
|
---|
| 104 | if (pFrame->pu8RGBBuf)
|
---|
| 105 | {
|
---|
| 106 | Assert(pFrame->cbRGBBuf);
|
---|
| 107 | RTMemFree(pFrame->pu8RGBBuf);
|
---|
| 108 | pFrame->cbRGBBuf = 0;
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | /**
|
---|
[75355] | 113 | * Frees a recording video frame.
|
---|
[74992] | 114 | *
|
---|
[96481] | 115 | * @returns VBox status code.
|
---|
[74992] | 116 | * @param pFrame Pointer to video frame to free. The pointer will be invalid after return.
|
---|
| 117 | */
|
---|
[75354] | 118 | void RecordingVideoFrameFree(PRECORDINGVIDEOFRAME pFrame)
|
---|
[74992] | 119 | {
|
---|
| 120 | if (!pFrame)
|
---|
| 121 | return;
|
---|
| 122 |
|
---|
[96481] | 123 | RecordingVideoFrameDestroy(pFrame);
|
---|
| 124 |
|
---|
| 125 | RTMemFree(pFrame);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | /**
|
---|
| 129 | * Frees a recording frame.
|
---|
| 130 | *
|
---|
| 131 | * @returns VBox status code.
|
---|
| 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 |
|
---|