master
c 92 lines 3.02 KB
Raw
1 /*
2 * HMP commands related to audio backends
3 *
4 * Copyright (c) 2003-2004 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25 #include "qemu/osdep.h"
26 #include "audio_int.h"
27 #include "monitor/hmp.h"
28 #include "monitor/monitor.h"
29 #include "qapi/error.h"
30 #include "qobject/qdict.h"
31 #include "qemu/error-report.h"
32
33 static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
34
35 void hmp_info_capture(MonitorHMP *hmp, const QDict *qdict)
36 {
37 int i;
38 CaptureState *s;
39
40 warn_report_once("'info capture' is deprecated since v10.2, to be removed");
41
42 for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {
43 monitor_hmp_printf(hmp, "[%d]: ", i);
44 s->ops.info (s->opaque);
45 }
46 }
47
48 void hmp_stopcapture(MonitorHMP *hmp, const QDict *qdict)
49 {
50 int i;
51 int n = qdict_get_int(qdict, "n");
52 CaptureState *s;
53
54 warn_report_once("'stopcapture' is deprecated since v10.2, to be removed");
55
56 for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {
57 if (i == n) {
58 s->ops.destroy (s->opaque);
59 QLIST_REMOVE (s, entries);
60 g_free (s);
61 return;
62 }
63 }
64 }
65
66 void hmp_wavcapture(MonitorHMP *hmp, const QDict *qdict)
67 {
68 const char *path = qdict_get_str(qdict, "path");
69 int freq = qdict_get_try_int(qdict, "freq", 44100);
70 int bits = qdict_get_try_int(qdict, "bits", 16);
71 int nchannels = qdict_get_try_int(qdict, "nchannels", 2);
72 const char *audiodev = qdict_get_str(qdict, "audiodev");
73 CaptureState *s;
74 Error *local_err = NULL;
75 AudioBackend *as = audio_be_by_name(audiodev, &local_err);
76
77 warn_report_once("'wavcapture' is deprecated since v10.2, to be removed");
78
79 if (!as) {
80 error_report_err(local_err);
81 return;
82 }
83
84 s = g_malloc0 (sizeof (*s));
85
86 if (wav_start_capture(as, s, path, freq, bits, nchannels)) {
87 monitor_hmp_printf(hmp, "Failed to add wave capture\n");
88 g_free (s);
89 return;
90 }
91 QLIST_INSERT_HEAD (&capture_head, s, entries);
92 }