VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/RecordingInternals.cpp@ 99085

Last change on this file since 99085 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1/* $Id: RecordingInternals.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * Recording internals code.
4 */
5
6/*
7 * Copyright (C) 2012-2023 Oracle and/or its affiliates.
8 *
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
26 */
27
28#include "RecordingInternals.h"
29
30#include <iprt/assert.h>
31#include <iprt/mem.h>
32
33#ifdef VBOX_WITH_AUDIO_RECORDING
34/**
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 */
43int 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 */
70static 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/**
81 * Frees a previously allocated recording audio frame.
82 *
83 * @param pFrame Audio frame to free. The pointer will be invalid after return.
84 */
85void RecordingAudioFrameFree(PRECORDINGAUDIOFRAME pFrame)
86{
87 if (!pFrame)
88 return;
89
90 recordingAudioFrameDestroy(pFrame);
91
92 RTMemFree(pFrame);
93 pFrame = NULL;
94}
95#endif
96
97/**
98 * Destroys a recording video frame.
99 *
100 * @param pFrame Pointer to video frame to destroy.
101 */
102void 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/**
113 * Frees a recording video frame.
114 *
115 * @returns VBox status code.
116 * @param pFrame Pointer to video frame to free. The pointer will be invalid after return.
117 */
118void RecordingVideoFrameFree(PRECORDINGVIDEOFRAME pFrame)
119{
120 if (!pFrame)
121 return;
122
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 */
134void RecordingFrameFree(PRECORDINGFRAME pFrame)
135{
136 if (!pFrame)
137 return;
138
139 switch (pFrame->enmType)
140 {
141#ifdef VBOX_WITH_AUDIO_RECORDING
142 case RECORDINGFRAME_TYPE_AUDIO:
143 recordingAudioFrameDestroy(&pFrame->Audio);
144 break;
145#endif
146 case RECORDINGFRAME_TYPE_VIDEO:
147 RecordingVideoFrameDestroy(&pFrame->Video);
148 break;
149
150 default:
151 AssertFailed();
152 break;
153 }
154
155 RTMemFree(pFrame);
156 pFrame = NULL;
157}
158
Note: See TracBrowser for help on using the repository browser.

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