1 | /* $Id: DrvAudioVideoRec.cpp 65205 2017-01-09 13:20:36Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Video recording audio backend for Main.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2016-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.215389.xyz. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_DRV_AUDIO
|
---|
23 | #include <VBox/log.h>
|
---|
24 | #include "DrvAudioVideoRec.h"
|
---|
25 | #include "ConsoleImpl.h"
|
---|
26 |
|
---|
27 | #include "Logging.h"
|
---|
28 |
|
---|
29 | #include "../../Devices/Audio/DrvAudio.h"
|
---|
30 | #include "../../Devices/Audio/AudioMixBuffer.h"
|
---|
31 | #include "EbmlWriter.h"
|
---|
32 |
|
---|
33 | #include <iprt/mem.h>
|
---|
34 | #include <iprt/cdefs.h>
|
---|
35 | #include <iprt/circbuf.h>
|
---|
36 |
|
---|
37 | #include <VBox/vmm/pdmaudioifs.h>
|
---|
38 | #include <VBox/vmm/pdmdrv.h>
|
---|
39 | #include <VBox/vmm/cfgm.h>
|
---|
40 | #include <VBox/err.h>
|
---|
41 |
|
---|
42 | #include <opus.h>
|
---|
43 |
|
---|
44 |
|
---|
45 | /*********************************************************************************************************************************
|
---|
46 | * Structures and Typedefs *
|
---|
47 | *********************************************************************************************************************************/
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Enumeration for audio/video recording driver recording mode.
|
---|
51 | */
|
---|
52 | typedef enum AVRECMODE
|
---|
53 | {
|
---|
54 | /** Unknown / invalid recording mode. */
|
---|
55 | AVRECMODE_UNKNOWN = 0,
|
---|
56 | /** Only record audio.
|
---|
57 | * This mode does not need to talk to the video recording driver,
|
---|
58 | * as this driver then simply creates an own WebM container. */
|
---|
59 | AVRECMODE_AUDIO = 1,
|
---|
60 | /** Records audio and video.
|
---|
61 | * Needs to work together with the video recording driver in
|
---|
62 | * order to get a full-featured WebM container. */
|
---|
63 | AVRECMODE_AUDIO_VIDEO = 2
|
---|
64 | } AVRECMODE;
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Structure for keeping codec specific data.
|
---|
68 | */
|
---|
69 | typedef struct AVRECCODEC
|
---|
70 | {
|
---|
71 | union
|
---|
72 | {
|
---|
73 | struct
|
---|
74 | {
|
---|
75 | /** Encoder we're going to use. */
|
---|
76 | OpusEncoder *pEnc;
|
---|
77 | } Opus;
|
---|
78 | };
|
---|
79 | } AVRECCODEC, *PAVRECCODEC;
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Audio video recording output stream.
|
---|
83 | */
|
---|
84 | typedef struct AVRECSTREAMOUT
|
---|
85 | {
|
---|
86 | /** Note: Always must come first! */
|
---|
87 | PDMAUDIOSTREAM Stream;
|
---|
88 | /** The PCM properties of this stream. */
|
---|
89 | PDMAUDIOPCMPROPS Props;
|
---|
90 | uint64_t old_ticks;
|
---|
91 | uint64_t cSamplesSentPerSec;
|
---|
92 | /** Codec data.
|
---|
93 | * As every stream can be different, one codec per stream is needed. */
|
---|
94 | AVRECCODEC Codec;
|
---|
95 | } AVRECSTREAMOUT, *PAVRECSTREAMOUT;
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Video recording audio driver instance data.
|
---|
99 | */
|
---|
100 | typedef struct DRVAUDIOVIDEOREC
|
---|
101 | {
|
---|
102 | /** Pointer to audio video recording object. */
|
---|
103 | AudioVideoRec *pAudioVideoRec;
|
---|
104 | /** Pointer to the driver instance structure. */
|
---|
105 | PPDMDRVINS pDrvIns;
|
---|
106 | /** Pointer to host audio interface. */
|
---|
107 | PDMIHOSTAUDIO IHostAudio;
|
---|
108 | /** Pointer to the DrvAudio port interface that is above us. */
|
---|
109 | PPDMIAUDIOCONNECTOR pDrvAudio;
|
---|
110 | /** Recording mode. */
|
---|
111 | AVRECMODE enmMode;
|
---|
112 | /** Pointer to WebM container to write recorded audio data to.
|
---|
113 | * See the AVRECMODE enumeration for more information. */
|
---|
114 | WebMWriter *pEBML;
|
---|
115 | } DRVAUDIOVIDEOREC, *PDRVAUDIOVIDEOREC;
|
---|
116 |
|
---|
117 | /** Makes DRVAUDIOVIDEOREC out of PDMIHOSTAUDIO. */
|
---|
118 | #define PDMIHOSTAUDIO_2_DRVAUDIOVIDEOREC(pInterface) \
|
---|
119 | ( (PDRVAUDIOVIDEOREC)((uintptr_t)pInterface - RT_OFFSETOF(DRVAUDIOVIDEOREC, IHostAudio)) )
|
---|
120 |
|
---|
121 |
|
---|
122 | static int avRecCreateStreamOut(PPDMIHOSTAUDIO pInterface,
|
---|
123 | PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
|
---|
124 | {
|
---|
125 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
126 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
127 | AssertPtrReturn(pCfgReq, VERR_INVALID_POINTER);
|
---|
128 | AssertPtrReturn(pCfgAcq, VERR_INVALID_POINTER);
|
---|
129 |
|
---|
130 | PAVRECSTREAMOUT pStreamOut = (PAVRECSTREAMOUT)pStream;
|
---|
131 |
|
---|
132 | int rc = DrvAudioHlpStreamCfgToProps(pCfgReq, &pStreamOut->Props);
|
---|
133 | if (RT_SUCCESS(rc))
|
---|
134 | {
|
---|
135 | OpusEncoder *pEnc = NULL;
|
---|
136 |
|
---|
137 | int orc;
|
---|
138 | pEnc = opus_encoder_create(48000 /* Hz */, 2 /* Stereo */, OPUS_APPLICATION_AUDIO, &orc);
|
---|
139 | if (orc != OPUS_OK)
|
---|
140 | {
|
---|
141 | LogRel(("VideoRec: Audio codec failed to initialize: %s\n", opus_strerror(orc)));
|
---|
142 | return VERR_AUDIO_BACKEND_INIT_FAILED;
|
---|
143 | }
|
---|
144 |
|
---|
145 | AssertPtr(pEnc);
|
---|
146 |
|
---|
147 | orc = opus_encoder_ctl(pEnc, OPUS_SET_BITRATE(pCfgReq->uHz));
|
---|
148 | if (orc != OPUS_OK)
|
---|
149 | {
|
---|
150 | LogRel(("VideoRec: Audio codec failed to set bitrate: %s\n", opus_strerror(orc)));
|
---|
151 | rc = VERR_AUDIO_BACKEND_INIT_FAILED;
|
---|
152 | }
|
---|
153 | else
|
---|
154 | {
|
---|
155 | pStreamOut->Codec.Opus.pEnc = pEnc;
|
---|
156 |
|
---|
157 | if (pCfgAcq)
|
---|
158 | pCfgAcq->cSampleBufferSize = _4K; /** @todo Make this configurable. */
|
---|
159 | }
|
---|
160 | }
|
---|
161 |
|
---|
162 | LogFlowFuncLeaveRC(VINF_SUCCESS);
|
---|
163 | return VINF_SUCCESS;
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 | static int avRecControlStreamOut(PPDMIHOSTAUDIO pInterface,
|
---|
168 | PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
|
---|
169 | {
|
---|
170 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
171 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
172 | RT_NOREF(enmStreamCmd);
|
---|
173 |
|
---|
174 | PDRVAUDIOVIDEOREC pThis = PDMIHOSTAUDIO_2_DRVAUDIOVIDEOREC(pInterface);
|
---|
175 | RT_NOREF(pThis);
|
---|
176 |
|
---|
177 | LogFlowFunc(("enmStreamCmd=%ld\n", enmStreamCmd));
|
---|
178 |
|
---|
179 | AudioMixBufReset(&pStream->MixBuf);
|
---|
180 |
|
---|
181 | return VINF_SUCCESS;
|
---|
182 | }
|
---|
183 |
|
---|
184 |
|
---|
185 | /**
|
---|
186 | * @interface_method_impl{PDMIHOSTAUDIO,pfnInit}
|
---|
187 | */
|
---|
188 | static DECLCALLBACK(int) drvAudioVideoRecInit(PPDMIHOSTAUDIO pInterface)
|
---|
189 | {
|
---|
190 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
191 |
|
---|
192 | LogFlowFuncEnter();
|
---|
193 |
|
---|
194 | PDRVAUDIOVIDEOREC pThis = PDMIHOSTAUDIO_2_DRVAUDIOVIDEOREC(pInterface);
|
---|
195 |
|
---|
196 | pThis->enmMode = AVRECMODE_AUDIO;
|
---|
197 |
|
---|
198 | int rc;
|
---|
199 |
|
---|
200 | try
|
---|
201 | {
|
---|
202 | switch (pThis->enmMode)
|
---|
203 | {
|
---|
204 | case AVRECMODE_AUDIO:
|
---|
205 | {
|
---|
206 | pThis->pEBML = new WebMWriter();
|
---|
207 | pThis->pEBML->create("/tmp/test.webm", WebMWriter::Mode_Audio); /** @todo FIX! */
|
---|
208 | break;
|
---|
209 | }
|
---|
210 |
|
---|
211 | case AVRECMODE_AUDIO_VIDEO:
|
---|
212 | {
|
---|
213 | break;
|
---|
214 | }
|
---|
215 |
|
---|
216 | default:
|
---|
217 | rc = VERR_NOT_SUPPORTED;
|
---|
218 | break;
|
---|
219 | }
|
---|
220 | }
|
---|
221 | catch (std::bad_alloc)
|
---|
222 | {
|
---|
223 | rc = VERR_NO_MEMORY;
|
---|
224 | }
|
---|
225 |
|
---|
226 | if (RT_FAILURE(rc))
|
---|
227 | {
|
---|
228 | LogRel(("VideoRec: Audio recording driver failed to initialize, rc=%Rrc\n", rc));
|
---|
229 | }
|
---|
230 | else
|
---|
231 | LogRel2(("VideoRec: Audio recording driver initialized\n"));
|
---|
232 |
|
---|
233 | return rc;
|
---|
234 | }
|
---|
235 |
|
---|
236 |
|
---|
237 | /**
|
---|
238 | * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCapture}
|
---|
239 | */
|
---|
240 | static DECLCALLBACK(int) drvAudioVideoRecStreamCapture(PPDMIHOSTAUDIO pInterface,
|
---|
241 | PPDMAUDIOSTREAM pStream, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead)
|
---|
242 | {
|
---|
243 | RT_NOREF(pInterface, pStream, pvBuf, cbBuf);
|
---|
244 |
|
---|
245 | if (pcbRead)
|
---|
246 | *pcbRead = 0;
|
---|
247 |
|
---|
248 | return VINF_SUCCESS;
|
---|
249 | }
|
---|
250 |
|
---|
251 |
|
---|
252 | /**
|
---|
253 | * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamPlay}
|
---|
254 | */
|
---|
255 | static DECLCALLBACK(int) drvAudioVideoRecStreamPlay(PPDMIHOSTAUDIO pInterface,
|
---|
256 | PPDMAUDIOSTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten)
|
---|
257 | {
|
---|
258 | RT_NOREF2(pvBuf, cbBuf);
|
---|
259 |
|
---|
260 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
261 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
262 | /* pcbWritten is optional. */
|
---|
263 |
|
---|
264 | PDRVAUDIOVIDEOREC pThis = PDMIHOSTAUDIO_2_DRVAUDIOVIDEOREC(pInterface);
|
---|
265 | PAVRECSTREAMOUT pStreamOut = (PAVRECSTREAMOUT)pStream;
|
---|
266 |
|
---|
267 | uint32_t cLive = AudioMixBufLive(&pStream->MixBuf);
|
---|
268 |
|
---|
269 | uint64_t now = PDMDrvHlpTMGetVirtualTime(pThis->pDrvIns);
|
---|
270 | uint64_t ticks = now - pStreamOut->old_ticks;
|
---|
271 | uint64_t ticks_per_second = PDMDrvHlpTMGetVirtualFreq(pThis->pDrvIns);
|
---|
272 |
|
---|
273 | /* Minimize the rounding error: samples = int((ticks * freq) / ticks_per_second + 0.5). */
|
---|
274 | uint32_t cSamplesPlayed = (int)((2 * ticks * pStreamOut->Props.uHz + ticks_per_second) / ticks_per_second / 2);
|
---|
275 |
|
---|
276 | /* Don't play more than available. */
|
---|
277 | if (cSamplesPlayed > cLive)
|
---|
278 | cSamplesPlayed = cLive;
|
---|
279 |
|
---|
280 | /* Remember when samples were consumed. */
|
---|
281 | pStreamOut->old_ticks = now;
|
---|
282 |
|
---|
283 | int cSamplesToSend = cSamplesPlayed;
|
---|
284 |
|
---|
285 | LogFlowFunc(("uFreq=%RU32, cChan=%RU8, cBits=%RU8, fSigned=%RTbool, cSamplesToSend=%RU32\n",
|
---|
286 | pStreamOut->Props.uHz, pStreamOut->Props.cChannels,
|
---|
287 | pStreamOut->Props.cBits, pStreamOut->Props.fSigned, cSamplesToSend));
|
---|
288 |
|
---|
289 | /*
|
---|
290 | * Call the encoder server with the data.
|
---|
291 | */
|
---|
292 | uint32_t cReadTotal = 0;
|
---|
293 |
|
---|
294 | uint8_t abDst[_4K];
|
---|
295 | opus_int32 cbDst = (opus_int32)sizeof(abDst);
|
---|
296 |
|
---|
297 | PPDMAUDIOSAMPLE pSamples;
|
---|
298 | uint32_t cRead;
|
---|
299 | int rc = AudioMixBufAcquire(&pStream->MixBuf, cSamplesToSend,
|
---|
300 | &pSamples, &cRead);
|
---|
301 | if ( RT_SUCCESS(rc)
|
---|
302 | && cRead)
|
---|
303 | {
|
---|
304 | cReadTotal = cRead;
|
---|
305 |
|
---|
306 | opus_int32 orc = opus_encode(pStreamOut->Codec.Opus.pEnc, (opus_int16 *)pSamples, cRead, abDst, cbDst);
|
---|
307 | if (orc != OPUS_OK)
|
---|
308 | LogFunc(("Encoding (1) failed: %s\n", opus_strerror(orc)));
|
---|
309 |
|
---|
310 | if (rc == VINF_TRY_AGAIN)
|
---|
311 | {
|
---|
312 | rc = AudioMixBufAcquire(&pStream->MixBuf, cSamplesToSend - cRead,
|
---|
313 | &pSamples, &cRead);
|
---|
314 |
|
---|
315 |
|
---|
316 |
|
---|
317 | cReadTotal += cRead;
|
---|
318 | }
|
---|
319 | }
|
---|
320 |
|
---|
321 | AudioMixBufFinish(&pStream->MixBuf, cSamplesToSend);
|
---|
322 |
|
---|
323 | /*
|
---|
324 | * Always report back all samples acquired, regardless of whether the
|
---|
325 | * encoder actually did process those.
|
---|
326 | */
|
---|
327 | if (pcbWritten)
|
---|
328 | *pcbWritten = cReadTotal;
|
---|
329 |
|
---|
330 | LogFlowFunc(("cReadTotal=%RU32, rc=%Rrc\n", cReadTotal, rc));
|
---|
331 | return rc;
|
---|
332 | }
|
---|
333 |
|
---|
334 |
|
---|
335 | static int avRecDestroyStreamOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
|
---|
336 | {
|
---|
337 | PDRVAUDIOVIDEOREC pThis = PDMIHOSTAUDIO_2_DRVAUDIOVIDEOREC(pInterface);
|
---|
338 | RT_NOREF(pThis);
|
---|
339 | PAVRECSTREAMOUT pStreamOut = (PAVRECSTREAMOUT)pStream;
|
---|
340 |
|
---|
341 | if (pStreamOut->Codec.Opus.pEnc)
|
---|
342 | {
|
---|
343 | opus_encoder_destroy(pStreamOut->Codec.Opus.pEnc);
|
---|
344 | pStreamOut->Codec.Opus.pEnc = NULL;
|
---|
345 | }
|
---|
346 |
|
---|
347 | return VINF_SUCCESS;
|
---|
348 | }
|
---|
349 |
|
---|
350 |
|
---|
351 | /**
|
---|
352 | * @interface_method_impl{PDMIHOSTAUDIO,pfnGetConfig}
|
---|
353 | */
|
---|
354 | static DECLCALLBACK(int) drvAudioVideoRecGetConfig(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pBackendCfg)
|
---|
355 | {
|
---|
356 | NOREF(pInterface);
|
---|
357 | AssertPtrReturn(pBackendCfg, VERR_INVALID_POINTER);
|
---|
358 |
|
---|
359 | pBackendCfg->cbStreamOut = sizeof(AVRECSTREAMOUT);
|
---|
360 | pBackendCfg->cbStreamIn = 0;
|
---|
361 | pBackendCfg->cMaxStreamsIn = 0;
|
---|
362 | pBackendCfg->cMaxStreamsOut = UINT32_MAX;
|
---|
363 |
|
---|
364 | return VINF_SUCCESS;
|
---|
365 | }
|
---|
366 |
|
---|
367 |
|
---|
368 | /**
|
---|
369 | * @interface_method_impl{PDMIHOSTAUDIO,pfnShutdown}
|
---|
370 | */
|
---|
371 | static DECLCALLBACK(void) drvAudioVideoRecShutdown(PPDMIHOSTAUDIO pInterface)
|
---|
372 | {
|
---|
373 | LogFlowFuncEnter();
|
---|
374 |
|
---|
375 | PDRVAUDIOVIDEOREC pThis = PDMIHOSTAUDIO_2_DRVAUDIOVIDEOREC(pInterface);
|
---|
376 |
|
---|
377 | int rc;
|
---|
378 |
|
---|
379 | switch (pThis->enmMode)
|
---|
380 | {
|
---|
381 | case AVRECMODE_AUDIO:
|
---|
382 | {
|
---|
383 | if (pThis->pEBML)
|
---|
384 | {
|
---|
385 | rc = pThis->pEBML->writeFooter(0 /* Hash */);
|
---|
386 | AssertRC(rc);
|
---|
387 |
|
---|
388 | pThis->pEBML->close();
|
---|
389 |
|
---|
390 | delete pThis->pEBML;
|
---|
391 | pThis->pEBML = NULL;
|
---|
392 | }
|
---|
393 | break;
|
---|
394 | }
|
---|
395 |
|
---|
396 | case AVRECMODE_AUDIO_VIDEO:
|
---|
397 | {
|
---|
398 | break;
|
---|
399 | }
|
---|
400 |
|
---|
401 | default:
|
---|
402 | rc = VERR_NOT_SUPPORTED;
|
---|
403 | break;
|
---|
404 | }
|
---|
405 |
|
---|
406 | LogFlowFuncLeaveRC(rc);
|
---|
407 | }
|
---|
408 |
|
---|
409 |
|
---|
410 | /**
|
---|
411 | * @interface_method_impl{PDMIHOSTAUDIO,pfnGetStatus}
|
---|
412 | */
|
---|
413 | static DECLCALLBACK(PDMAUDIOBACKENDSTS) drvAudioVideoRecGetStatus(PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir)
|
---|
414 | {
|
---|
415 | RT_NOREF(enmDir);
|
---|
416 | AssertPtrReturn(pInterface, PDMAUDIOBACKENDSTS_UNKNOWN);
|
---|
417 |
|
---|
418 | return PDMAUDIOBACKENDSTS_RUNNING;
|
---|
419 | }
|
---|
420 |
|
---|
421 |
|
---|
422 | /**
|
---|
423 | * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCreate}
|
---|
424 | */
|
---|
425 | static DECLCALLBACK(int) drvAudioVideoRecStreamCreate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream,
|
---|
426 | PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
|
---|
427 | {
|
---|
428 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
429 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
430 | AssertPtrReturn(pCfgReq, VERR_INVALID_POINTER);
|
---|
431 | AssertPtrReturn(pCfgAcq, VERR_INVALID_POINTER);
|
---|
432 |
|
---|
433 | if (pCfgReq->enmDir == PDMAUDIODIR_OUT)
|
---|
434 | return avRecCreateStreamOut(pInterface, pStream, pCfgReq, pCfgAcq);
|
---|
435 |
|
---|
436 | return VERR_NOT_SUPPORTED;
|
---|
437 | }
|
---|
438 |
|
---|
439 |
|
---|
440 | /**
|
---|
441 | * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamDestroy}
|
---|
442 | */
|
---|
443 | static DECLCALLBACK(int) drvAudioVideoRecStreamDestroy(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
|
---|
444 | {
|
---|
445 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
446 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
447 |
|
---|
448 | if (pStream->enmDir == PDMAUDIODIR_OUT)
|
---|
449 | return avRecDestroyStreamOut(pInterface, pStream);
|
---|
450 |
|
---|
451 | return VINF_SUCCESS;
|
---|
452 | }
|
---|
453 |
|
---|
454 |
|
---|
455 | /**
|
---|
456 | * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamControl}
|
---|
457 | */
|
---|
458 | static DECLCALLBACK(int) drvAudioVideoRecStreamControl(PPDMIHOSTAUDIO pInterface,
|
---|
459 | PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
|
---|
460 | {
|
---|
461 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
462 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
463 |
|
---|
464 | Assert(pStream->enmCtx == PDMAUDIOSTREAMCTX_HOST);
|
---|
465 |
|
---|
466 | if (pStream->enmDir == PDMAUDIODIR_OUT)
|
---|
467 | return avRecControlStreamOut(pInterface, pStream, enmStreamCmd);
|
---|
468 |
|
---|
469 | return VINF_SUCCESS;
|
---|
470 | }
|
---|
471 |
|
---|
472 |
|
---|
473 | /**
|
---|
474 | * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetStatus}
|
---|
475 | */
|
---|
476 | static DECLCALLBACK(PDMAUDIOSTRMSTS) drvAudioVideoRecStreamGetStatus(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
|
---|
477 | {
|
---|
478 | NOREF(pInterface);
|
---|
479 | NOREF(pStream);
|
---|
480 |
|
---|
481 | return ( PDMAUDIOSTRMSTS_FLAG_INITIALIZED | PDMAUDIOSTRMSTS_FLAG_ENABLED
|
---|
482 | | PDMAUDIOSTRMSTS_FLAG_DATA_READABLE | PDMAUDIOSTRMSTS_FLAG_DATA_WRITABLE);
|
---|
483 | }
|
---|
484 |
|
---|
485 |
|
---|
486 | /**
|
---|
487 | * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamIterate}
|
---|
488 | */
|
---|
489 | static DECLCALLBACK(int) drvAudioVideoRecStreamIterate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
|
---|
490 | {
|
---|
491 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
492 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
493 |
|
---|
494 | LogFlowFuncEnter();
|
---|
495 |
|
---|
496 | /* Nothing to do here for video recording. */
|
---|
497 | return VINF_SUCCESS;
|
---|
498 | }
|
---|
499 |
|
---|
500 |
|
---|
501 | /**
|
---|
502 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
503 | */
|
---|
504 | static DECLCALLBACK(void *) drvAudioVideoRecQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
505 | {
|
---|
506 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
507 | PDRVAUDIOVIDEOREC pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVIDEOREC);
|
---|
508 |
|
---|
509 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
510 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudio);
|
---|
511 | return NULL;
|
---|
512 | }
|
---|
513 |
|
---|
514 |
|
---|
515 | AudioVideoRec::AudioVideoRec(Console *pConsole)
|
---|
516 | : mpDrv(NULL),
|
---|
517 | mParent(pConsole)
|
---|
518 | {
|
---|
519 | }
|
---|
520 |
|
---|
521 |
|
---|
522 | AudioVideoRec::~AudioVideoRec(void)
|
---|
523 | {
|
---|
524 | if (mpDrv)
|
---|
525 | {
|
---|
526 | mpDrv->pAudioVideoRec = NULL;
|
---|
527 | mpDrv = NULL;
|
---|
528 | }
|
---|
529 | }
|
---|
530 |
|
---|
531 |
|
---|
532 | /**
|
---|
533 | * Construct a audio video recording driver instance.
|
---|
534 | *
|
---|
535 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
536 | */
|
---|
537 | /* static */
|
---|
538 | DECLCALLBACK(int) AudioVideoRec::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
539 | {
|
---|
540 | RT_NOREF(fFlags);
|
---|
541 |
|
---|
542 | PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
|
---|
543 | PDRVAUDIOVIDEOREC pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVIDEOREC);
|
---|
544 |
|
---|
545 | AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
|
---|
546 | AssertPtrReturn(pCfg, VERR_INVALID_POINTER);
|
---|
547 |
|
---|
548 | LogRel(("Audio: Initializing video recording audio driver\n"));
|
---|
549 | LogFlowFunc(("fFlags=0x%x\n", fFlags));
|
---|
550 |
|
---|
551 | AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
|
---|
552 | ("Configuration error: Not possible to attach anything to this driver!\n"),
|
---|
553 | VERR_PDM_DRVINS_NO_ATTACH);
|
---|
554 |
|
---|
555 | /*
|
---|
556 | * Init the static parts.
|
---|
557 | */
|
---|
558 | pThis->pDrvIns = pDrvIns;
|
---|
559 | /* IBase */
|
---|
560 | pDrvIns->IBase.pfnQueryInterface = drvAudioVideoRecQueryInterface;
|
---|
561 | /* IHostAudio */
|
---|
562 | PDMAUDIO_IHOSTAUDIO_CALLBACKS(drvAudioVideoRec);
|
---|
563 |
|
---|
564 | /*
|
---|
565 | * Get the AudioVideoRec object pointer.
|
---|
566 | */
|
---|
567 | void *pvUser = NULL;
|
---|
568 | int rc = CFGMR3QueryPtr(pCfg, "Object", &pvUser); /** @todo r=andy Get rid of this hack and use IHostAudio::SetCallback. */
|
---|
569 | AssertMsgRCReturn(rc, ("Confguration error: No/bad \"Object\" value, rc=%Rrc\n", rc), rc);
|
---|
570 |
|
---|
571 | pThis->pAudioVideoRec = (AudioVideoRec *)pvUser;
|
---|
572 | pThis->pAudioVideoRec->mpDrv = pThis;
|
---|
573 |
|
---|
574 | /*
|
---|
575 | * Get the interface for the above driver (DrvAudio) to make mixer/conversion calls.
|
---|
576 | * Described in CFGM tree.
|
---|
577 | */
|
---|
578 | pThis->pDrvAudio = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIAUDIOCONNECTOR);
|
---|
579 | AssertMsgReturn(pThis->pDrvAudio, ("Configuration error: No upper interface specified!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
|
---|
580 |
|
---|
581 | return VINF_SUCCESS;
|
---|
582 | }
|
---|
583 |
|
---|
584 |
|
---|
585 | /**
|
---|
586 | * @interface_method_impl{PDMDRVREG,pfnDestruct}
|
---|
587 | */
|
---|
588 | /* static */
|
---|
589 | DECLCALLBACK(void) AudioVideoRec::drvDestruct(PPDMDRVINS pDrvIns)
|
---|
590 | {
|
---|
591 | PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
|
---|
592 | PDRVAUDIOVIDEOREC pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVIDEOREC);
|
---|
593 | LogFlowFuncEnter();
|
---|
594 |
|
---|
595 | /*
|
---|
596 | * If the AudioVideoRec object is still alive, we must clear it's reference to
|
---|
597 | * us since we'll be invalid when we return from this method.
|
---|
598 | */
|
---|
599 | if (pThis->pAudioVideoRec)
|
---|
600 | {
|
---|
601 | pThis->pAudioVideoRec->mpDrv = NULL;
|
---|
602 | pThis->pAudioVideoRec = NULL;
|
---|
603 | }
|
---|
604 | }
|
---|
605 |
|
---|
606 |
|
---|
607 | /**
|
---|
608 | * Video recording audio driver registration record.
|
---|
609 | */
|
---|
610 | const PDMDRVREG AudioVideoRec::DrvReg =
|
---|
611 | {
|
---|
612 | PDM_DRVREG_VERSION,
|
---|
613 | /* szName */
|
---|
614 | "AudioVideoRec",
|
---|
615 | /* szRCMod */
|
---|
616 | "",
|
---|
617 | /* szR0Mod */
|
---|
618 | "",
|
---|
619 | /* pszDescription */
|
---|
620 | "Audio driver for video recording",
|
---|
621 | /* fFlags */
|
---|
622 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
623 | /* fClass. */
|
---|
624 | PDM_DRVREG_CLASS_AUDIO,
|
---|
625 | /* cMaxInstances */
|
---|
626 | ~0U,
|
---|
627 | /* cbInstance */
|
---|
628 | sizeof(DRVAUDIOVIDEOREC),
|
---|
629 | /* pfnConstruct */
|
---|
630 | AudioVideoRec::drvConstruct,
|
---|
631 | /* pfnDestruct */
|
---|
632 | AudioVideoRec::drvDestruct,
|
---|
633 | /* pfnRelocate */
|
---|
634 | NULL,
|
---|
635 | /* pfnIOCtl */
|
---|
636 | NULL,
|
---|
637 | /* pfnPowerOn */
|
---|
638 | NULL,
|
---|
639 | /* pfnReset */
|
---|
640 | NULL,
|
---|
641 | /* pfnSuspend */
|
---|
642 | NULL,
|
---|
643 | /* pfnResume */
|
---|
644 | NULL,
|
---|
645 | /* pfnAttach */
|
---|
646 | NULL,
|
---|
647 | /* pfnDetach */
|
---|
648 | NULL,
|
---|
649 | /* pfnPowerOff */
|
---|
650 | NULL,
|
---|
651 | /* pfnSoftReset */
|
---|
652 | NULL,
|
---|
653 | /* u32EndVersion */
|
---|
654 | PDM_DRVREG_VERSION
|
---|
655 | };
|
---|
656 |
|
---|