audio-hmp-cmds.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #include "qemu/osdep.h"
  25. #include "audio/audio.h"
  26. #include "monitor/hmp.h"
  27. #include "monitor/monitor.h"
  28. #include "qapi/error.h"
  29. #include "qobject/qdict.h"
  30. static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
  31. void hmp_info_capture(Monitor *mon, const QDict *qdict)
  32. {
  33. int i;
  34. CaptureState *s;
  35. for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {
  36. monitor_printf(mon, "[%d]: ", i);
  37. s->ops.info (s->opaque);
  38. }
  39. }
  40. void hmp_stopcapture(Monitor *mon, const QDict *qdict)
  41. {
  42. int i;
  43. int n = qdict_get_int(qdict, "n");
  44. CaptureState *s;
  45. for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {
  46. if (i == n) {
  47. s->ops.destroy (s->opaque);
  48. QLIST_REMOVE (s, entries);
  49. g_free (s);
  50. return;
  51. }
  52. }
  53. }
  54. void hmp_wavcapture(Monitor *mon, const QDict *qdict)
  55. {
  56. const char *path = qdict_get_str(qdict, "path");
  57. int freq = qdict_get_try_int(qdict, "freq", 44100);
  58. int bits = qdict_get_try_int(qdict, "bits", 16);
  59. int nchannels = qdict_get_try_int(qdict, "nchannels", 2);
  60. const char *audiodev = qdict_get_str(qdict, "audiodev");
  61. CaptureState *s;
  62. Error *local_err = NULL;
  63. AudioState *as = audio_state_by_name(audiodev, &local_err);
  64. if (!as) {
  65. error_report_err(local_err);
  66. return;
  67. }
  68. s = g_malloc0 (sizeof (*s));
  69. if (wav_start_capture(as, s, path, freq, bits, nchannels)) {
  70. monitor_printf(mon, "Failed to add wave capture\n");
  71. g_free (s);
  72. return;
  73. }
  74. QLIST_INSERT_HEAD (&capture_head, s, entries);
  75. }