summaryrefslogtreecommitdiffstats
path: root/src/VBox/Devices/Audio/AudioTestService.h
blob: d7f6c65152cb21be29bc5077664267fd7fcd3e52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/* $Id: AudioTestService.h $ */
/** @file
 * AudioTestService - Audio test execution server, Public Header.
 */

/*
 * Copyright (C) 2021-2023 Oracle and/or its affiliates.
 *
 * This file is part of VirtualBox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, in version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses>.
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#ifndef VBOX_INCLUDED_SRC_Audio_AudioTestService_h
#define VBOX_INCLUDED_SRC_Audio_AudioTestService_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif

#include <iprt/tcp.h>

#include "AudioTestServiceInternal.h"

extern const PCATSTRANSPORT g_apTransports[];
extern const size_t         g_cTransports;

/** Default TCP/IP bind port the guest ATS (Audio Test Service) is listening on. */
#define ATS_TCP_DEF_BIND_PORT_GUEST                6042
/** Default TCP/IP bind port the host ATS is listening on. */
#define ATS_TCP_DEF_BIND_PORT_HOST                 6052
/** Default TCP/IP ATS bind port the ValidationKit Audio Driver ATS is listening on. */
#define ATS_TCP_DEF_BIND_PORT_VALKIT               6062
/** Default TCP/IP port the guest ATS is connecting to. */
#define ATS_TCP_DEF_CONNECT_PORT_GUEST              ATS_TCP_DEF_BIND_PORT_HOST
/** Default TCP/IP port the host ATS is connecting to the guest (needs NAT port forwarding). */
#define ATS_TCP_DEF_CONNECT_PORT_HOST_PORT_FWD     6072
/** Default TCP/IP port the host ATS is connecting to. */
#define ATS_TCP_DEF_CONNECT_PORT_VALKIT            ATS_TCP_DEF_BIND_PORT_VALKIT
/** Default TCP/IP address the host is connecting to. */
#define ATS_TCP_DEF_CONNECT_HOST_ADDR_STR          "127.0.0.1"
/** Default TCP/IP address the guest ATS connects to when
 *  running in client mode (reversed mode, needed for NATed VMs). */
#define ATS_TCP_DEF_CONNECT_GUEST_STR              "10.0.2.2"

/**
 * Structure for keeping an Audio Test Service (ATS) callback table.
 */
typedef struct ATSCALLBACKS
{
    /**
     * Tells the implementation that a new client connected. Optional.
     *
     * @param   pvUser          User-supplied pointer to context data. Optional.
     */
    DECLR3CALLBACKMEMBER(int, pfnHowdy, (void const *pvUser));

    /**
     * Tells the implementation that a client disconnected. Optional.
     *
     * @param   pvUser          User-supplied pointer to context data. Optional.
     */
    DECLR3CALLBACKMEMBER(int, pfnBye, (void const *pvUser));

    /**
     * Begins a test set. Optional.
     *
     * @returns VBox status code.
     * @param   pvUser          User-supplied pointer to context data. Optional.
     * @param   pszTag          Tag of test set to begin.
     */
    DECLR3CALLBACKMEMBER(int, pfnTestSetBegin, (void const *pvUser, const char *pszTag));

    /**
     * Ends the current test set. Optional.
     *
     * @returns VBox status code.
     * @param   pvUser          User-supplied pointer to context data. Optional.
     * @param   pszTag          Tag of test set to end.
     */
    DECLR3CALLBACKMEMBER(int, pfnTestSetEnd,   (void const *pvUser, const char *pszTag));

    /**
     * Marks the begin of sending a test set. Optional.
     *
     * @returns VBox status code.
     * @param   pvUser          User-supplied pointer to context data. Optional.
     * @param   pszTag          Tag of test set to begin sending.
     */
    DECLR3CALLBACKMEMBER(int, pfnTestSetSendBegin, (void const *pvUser, const char *pszTag));

    /**
     * Reads data from a test set for sending it.
     *
     * @returns VBox status code.
     * @param   pvUser          User-supplied pointer to context data. Optional.
     * @param   pszTag          Tag of test set to begin sending.
     * @param   pvBuf           Where to store the read test set data.
     * @param   cbBuf           Size of \a pvBuf (in bytes).
     * @param   pcbRead         Where to return the amount of read data in bytes. Optional and can be NULL.
     */
    DECLR3CALLBACKMEMBER(int, pfnTestSetSendRead,  (void const *pvUser, const char *pszTag, void *pvBuf, size_t cbBuf, size_t *pcbRead));

    /**
     * Marks the end of sending a test set. Optional.
     *
     * @returns VBox status code.
     * @param   pvUser          User-supplied pointer to context data. Optional.
     * @param   pszTag          Tag of test set to end sending.
     */
    DECLR3CALLBACKMEMBER(int, pfnTestSetSendEnd,   (void const *pvUser, const char *pszTag));

    /**
     * Plays a test tone.
     *
     * @returns VBox status code.
     * @param   pvUser          User-supplied pointer to context data. Optional.
     * @param   pToneParms      Tone parameters to use for playback.
     */
    DECLR3CALLBACKMEMBER(int, pfnTonePlay, (void const *pvUser, PAUDIOTESTTONEPARMS pToneParms));

    /**
     * Records a test tone.
     *
     * @returns VBox status code.
     * @param   pvUser          User-supplied pointer to context data. Optional.
     * @param   pToneParms      Tone parameters to use for recording.
     */
    DECLR3CALLBACKMEMBER(int, pfnToneRecord, (void const *pvUser, PAUDIOTESTTONEPARMS pToneParms));

    /** Pointer to opaque user-provided context data. */
    void const *pvUser;
} ATSCALLBACKS;
/** Pointer to a const ATS callbacks table. */
typedef const struct ATSCALLBACKS *PCATSCALLBACKS;

/**
 * Structure for keeping an Audio Test Service (ATS) instance.
 */
typedef struct ATSSERVER
{
    /** Pointer to the selected transport layer. */
    PCATSTRANSPORT       pTransport;
    /** Pointer to the transport instance. */
    PATSTRANSPORTINST    pTransportInst;
    /** The callbacks table. */
    ATSCALLBACKS         Callbacks;
    /** Whether server is in started state or not. */
    bool volatile        fStarted;
    /** Whether to terminate or not. */
    bool volatile        fTerminate;
    /** The main thread's poll set to handle new clients. */
    RTPOLLSET            hPollSet;
    /** Pipe for communicating with the serving thread about new clients. - read end */
    RTPIPE               hPipeR;
    /** Pipe for communicating with the serving thread about new clients. - write end */
    RTPIPE               hPipeW;
    /** Main thread waiting for connections. */
    RTTHREAD             hThreadMain;
    /** Thread serving connected clients. */
    RTTHREAD             hThreadServing;
    /** Critical section protecting the list of new clients. */
    RTCRITSECT           CritSectClients;
    /** List of new clients waiting to be picked up by the client worker thread. */
    RTLISTANCHOR         LstClientsNew;
} ATSSERVER;
/** Pointer to an Audio Test Service (ATS) instance. */
typedef ATSSERVER *PATSSERVER;

int AudioTestSvcInit(PATSSERVER pThis, PCATSCALLBACKS pCallbacks);
int AudioTestSvcDestroy(PATSSERVER pThis);
int AudioTestSvcHandleOption(PATSSERVER pThis, int ch, PCRTGETOPTUNION pVal);
int AudioTestSvcStart(PATSSERVER pThis);
int AudioTestSvcStop(PATSSERVER pThis);

/**
 * Enumeration for the server connection mode.
 * Only applies to certain transport implementation like TCP/IP.
 */
typedef enum ATSCONNMODE
{
    /** Both: Uses parallel client and server connection methods (via threads). */
    ATSCONNMODE_BOTH = 0,
    /** Client only: Connects to a server. */
    ATSCONNMODE_CLIENT,
    /** Server only: Listens for new incoming client connections. */
    ATSCONNMODE_SERVER,
    /** 32bit hack. */
    ATSCONNMODE_32BIT_HACK = 0x7fffffff
} ATSCONNMODE;

/** TCP/IP options for the ATS server.
 *  @todo Make this more abstract later. */
enum ATSTCPOPT
{
    ATSTCPOPT_CONN_MODE = 5000,
    ATSTCPOPT_BIND_ADDRESS,
    ATSTCPOPT_BIND_PORT,
    ATSTCPOPT_CONNECT_ADDRESS,
    ATSTCPOPT_CONNECT_PORT
};

#endif /* !VBOX_INCLUDED_SRC_Audio_AudioTestService_h */