All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kővágó, Zoltán" <dirty.ice.hu@gmail.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH v5 06/14] coreaudio: port to -audiodev config
Date: Wed, 20 Feb 2019 22:37:35 +0100	[thread overview]
Message-ID: <5360bea19c08b79cb618e0cd304bebd36643cf3e.1550698466.git.DirtY.iCE.hu@gmail.com> (raw)
In-Reply-To: <cover.1550698466.git.DirtY.iCE.hu@gmail.com>

Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
---
 audio/audio_legacy.c | 28 +++++++++++++++++++++++++
 audio/coreaudio.c    | 49 ++++++++++----------------------------------
 2 files changed, 39 insertions(+), 38 deletions(-)

diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c
index 91ec6a3de1..086011fbff 100644
--- a/audio/audio_legacy.c
+++ b/audio/audio_legacy.c
@@ -109,6 +109,17 @@ static uint32_t frames_to_usecs(uint32_t frames,
     return (frames * 1000000 + freq / 2) / freq;
 }
 
+
+static void get_frames_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
+                                AudiodevPerDirectionOptions *pdo)
+{
+    const char *val = getenv(env);
+    if (val) {
+        *dst = frames_to_usecs(toui32(val), pdo);
+        *has_dst = true;
+    }
+}
+
 /* backend specific functions */
 /* ALSA */
 static void handle_alsa_per_direction(
@@ -156,6 +167,19 @@ static void handle_alsa(Audiodev *dev)
                         &aopt->threshold, &aopt->has_threshold);
 }
 
+/* coreaudio */
+static void handle_coreaudio(Audiodev *dev)
+{
+    get_frames_to_usecs(
+        "QEMU_COREAUDIO_BUFFER_SIZE",
+        &dev->u.coreaudio.out->buffer_len,
+        &dev->u.coreaudio.out->has_buffer_len,
+        qapi_AudiodevCoreaudioPerDirectionOptions_base(dev->u.coreaudio.out));
+    get_int("QEMU_COREAUDIO_BUFFER_COUNT",
+            &dev->u.coreaudio.out->buffer_count,
+            &dev->u.coreaudio.out->has_buffer_count);
+}
+
 /* general */
 static void handle_per_direction(
     AudiodevPerDirectionOptions *pdo, const char *prefix)
@@ -201,6 +225,10 @@ static AudiodevListEntry *legacy_opt(const char *drvname)
         handle_alsa(e->dev);
         break;
 
+    case AUDIODEV_DRIVER_COREAUDIO:
+        handle_coreaudio(e->dev);
+        break;
+
     default:
         break;
     }
diff --git a/audio/coreaudio.c b/audio/coreaudio.c
index 7d4225dbee..1ee43b7d5f 100644
--- a/audio/coreaudio.c
+++ b/audio/coreaudio.c
@@ -36,11 +36,6 @@
 #define MAC_OS_X_VERSION_10_6 1060
 #endif
 
-typedef struct {
-    int buffer_frames;
-    int nbuffers;
-} CoreaudioConf;
-
 typedef struct coreaudioVoiceOut {
     HWVoiceOut hw;
     pthread_mutex_t mutex;
@@ -507,7 +502,9 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
     int err;
     const char *typ = "playback";
     AudioValueRange frameRange;
-    CoreaudioConf *conf = drv_opaque;
+    Audiodev *dev = drv_opaque;
+    AudiodevCoreaudioPerDirectionOptions *cpdo = dev->u.coreaudio.out;
+    int frames;
 
     /* create mutex */
     err = pthread_mutex_init(&core->mutex, NULL);
@@ -538,16 +535,17 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
         return -1;
     }
 
-    if (frameRange.mMinimum > conf->buffer_frames) {
+    frames = audio_buffer_frames(
+        qapi_AudiodevCoreaudioPerDirectionOptions_base(cpdo), as, 11610);
+    if (frameRange.mMinimum > frames) {
         core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum;
         dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum);
-    }
-    else if (frameRange.mMaximum < conf->buffer_frames) {
+    } else if (frameRange.mMaximum < frames) {
         core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum;
         dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum);
     }
     else {
-        core->audioDevicePropertyBufferFrameSize = conf->buffer_frames;
+        core->audioDevicePropertyBufferFrameSize = frames;
     }
 
     /* set Buffer Frame Size */
@@ -568,7 +566,8 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
                            "Could not get device buffer frame size\n");
         return -1;
     }
-    hw->samples = conf->nbuffers * core->audioDevicePropertyBufferFrameSize;
+    hw->samples = (cpdo->has_buffer_count ? cpdo->buffer_count : 4) *
+        core->audioDevicePropertyBufferFrameSize;
 
     /* get StreamFormat */
     status = coreaudio_get_streamformat(core->outputDeviceID,
@@ -680,40 +679,15 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)
     return 0;
 }
 
-static CoreaudioConf glob_conf = {
-    .buffer_frames = 512,
-    .nbuffers = 4,
-};
-
 static void *coreaudio_audio_init(Audiodev *dev)
 {
-    CoreaudioConf *conf = g_malloc(sizeof(CoreaudioConf));
-    *conf = glob_conf;
-
-    return conf;
+    return dev;
 }
 
 static void coreaudio_audio_fini (void *opaque)
 {
-    g_free(opaque);
 }
 
-static struct audio_option coreaudio_options[] = {
-    {
-        .name  = "BUFFER_SIZE",
-        .tag   = AUD_OPT_INT,
-        .valp  = &glob_conf.buffer_frames,
-        .descr = "Size of the buffer in frames"
-    },
-    {
-        .name  = "BUFFER_COUNT",
-        .tag   = AUD_OPT_INT,
-        .valp  = &glob_conf.nbuffers,
-        .descr = "Number of buffers"
-    },
-    { /* End of list */ }
-};
-
 static struct audio_pcm_ops coreaudio_pcm_ops = {
     .init_out = coreaudio_init_out,
     .fini_out = coreaudio_fini_out,
@@ -725,7 +699,6 @@ static struct audio_pcm_ops coreaudio_pcm_ops = {
 static struct audio_driver coreaudio_audio_driver = {
     .name           = "coreaudio",
     .descr          = "CoreAudio http://developer.apple.com/audio/coreaudio.html",
-    .options        = coreaudio_options,
     .init           = coreaudio_audio_init,
     .fini           = coreaudio_audio_fini,
     .pcm_ops        = &coreaudio_pcm_ops,
-- 
2.20.1

  parent reply	other threads:[~2019-02-20 21:38 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-20 21:37 [Qemu-devel] [PATCH v5 00/14] Audio patches Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 01/14] qapi: qapi for audio backends Kővágó, Zoltán
2019-02-21 10:49   ` Gerd Hoffmann
2019-02-26  6:56   ` Markus Armbruster
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 02/14] audio: use qapi AudioFormat instead of audfmt_e Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 03/14] audio: -audiodev command line option: documentation Kővágó, Zoltán
2019-02-22 13:40   ` [Qemu-devel] [libvirt] " Daniel P. Berrangé
2019-02-22 14:09     ` Pavel Hrdina
2019-02-22 14:22     ` Gerd Hoffmann
2019-02-22 14:29       ` Daniel P. Berrangé
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 04/14] audio: -audiodev command line option basic implementation Kővágó, Zoltán
2019-02-26  1:39   ` Zoltán Kővágó
2019-03-07 15:56     ` Gerd Hoffmann
2019-03-08  0:45       ` Zoltán Kővágó
2019-03-08  7:21         ` Markus Armbruster
2019-03-08 19:40           ` Zoltán Kővágó
2019-03-11  6:42             ` Gerd Hoffmann
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 05/14] alsaaudio: port to -audiodev config Kővágó, Zoltán
2019-02-20 21:37 ` Kővágó, Zoltán [this message]
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 07/14] dsoundaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 08/14] noaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 09/14] ossaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 10/14] paaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 11/14] sdlaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 12/14] spiceaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 13/14] wavaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 14/14] audio: -audiodev command line option: cleanup Kővágó, Zoltán

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5360bea19c08b79cb618e0cd304bebd36643cf3e.1550698466.git.DirtY.iCE.hu@gmail.com \
    --to=dirty.ice.hu@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.