diff mbox

[2/3] wavcapture: Use stdio instead of QEMUFile

Message ID ebeeae79a7d9b9729866b9feb21af2fc4d899f18.1316524116.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela Sept. 20, 2011, 1:16 p.m. UTC
QEMUFile * is only intended for migration nowadays.  Using it for
anything else just adds pain and a layer of buffers for no good
reason.

Signed-off-by: Juan Quintela <quintela@redhat.com>
CC: malc <av1474@comtv.ru>

---
 audio/wavcapture.c |   48 ++++++++++++++++++++++++++++++++++--------------
 1 files changed, 34 insertions(+), 14 deletions(-)

Comments

malc Sept. 20, 2011, 1:57 p.m. UTC | #1
On Tue, 20 Sep 2011, Juan Quintela wrote:

> QEMUFile * is only intended for migration nowadays.  Using it for
> anything else just adds pain and a layer of buffers for no good
> reason.

I've commited two wav patches with some stylistic and changes.

[..snip..]
diff mbox

Patch

diff --git a/audio/wavcapture.c b/audio/wavcapture.c
index c64f0ef..9019995 100644
--- a/audio/wavcapture.c
+++ b/audio/wavcapture.c
@@ -3,7 +3,7 @@ 
 #include "audio.h"

 typedef struct {
-    QEMUFile *f;
+    FILE *f;
     int bytes;
     char *path;
     int freq;
@@ -40,12 +40,22 @@  static void wav_destroy (void *opaque)
         le_store (rlen, rifflen, 4);
         le_store (dlen, datalen, 4);

-        qemu_fseek (wav->f, 4, SEEK_SET);
-        qemu_put_buffer (wav->f, rlen, 4);
-
-        qemu_fseek (wav->f, 32, SEEK_CUR);
-        qemu_put_buffer (wav->f, dlen, 4);
-        qemu_fclose (wav->f);
+        fseek (wav->f, 4, SEEK_SET);
+        if (fseek (wav->f, 4, SEEK_SET) == -1) {
+            printf ("wav_destroy: fseek error %s\n", strerror(errno));
+        }
+        if (fwrite (rlen, 1, 4, wav->f) != 4) {
+            printf ("wav_destroy: fwrite error writing rlen '%s'\n",
+                    strerror(errno));
+        }
+        if (fseek (wav->f, 32, SEEK_CUR) == -1) {
+            printf ("wav_destroy: fseek error '%s'\n", strerror(errno));
+        }
+        if (fwrite (dlen, 1, 4, wav->f) != 4) {
+            printf ("wav_destroy: fwrite error writing dlen '%s'\n",
+                    strerror(errno));
+        }
+        fclose (wav->f);
     }

     g_free (wav->path);
@@ -55,7 +65,10 @@  static void wav_capture (void *opaque, void *buf, int size)
 {
     WAVState *wav = opaque;

-    qemu_put_buffer (wav->f, buf, size);
+    if (fwrite (buf, size, 1, wav->f) != 1) {
+        printf ("wav_capture: fwrite error '%s'\n",
+                strerror(errno));
+    }
     wav->bytes += size;
 }

@@ -130,7 +143,7 @@  int wav_start_capture (CaptureState *s, const char *path, int freq,
     le_store (hdr + 28, freq << shift, 4);
     le_store (hdr + 32, 1 << shift, 2);

-    wav->f = qemu_fopen (path, "wb");
+    wav->f = fopen (path, "wb");
     if (!wav->f) {
         monitor_printf(mon, "Failed to open wave file `%s'\nReason: %s\n",
                        path, strerror (errno));
@@ -143,19 +156,26 @@  int wav_start_capture (CaptureState *s, const char *path, int freq,
     wav->nchannels = nchannels;
     wav->freq = freq;

-    qemu_put_buffer (wav->f, hdr, sizeof (hdr));
+    if (fwrite (hdr, sizeof (hdr), 1, wav->f) != 1) {
+        monitor_printf (mon, "Failed to write header '%s'\n",
+                        strerror(errno));
+        goto error_free;
+    }

     cap = AUD_add_capture (&as, &ops, wav);
     if (!cap) {
         monitor_printf(mon, "Failed to add audio capture\n");
-        g_free (wav->path);
-        qemu_fclose (wav->f);
-        g_free (wav);
-        return -1;
+        goto error_free;
     }

     wav->cap = cap;
     s->opaque = wav;
     s->ops = wav_capture_ops;
     return 0;
+
+error_free:
+    g_free (wav->path);
+    fclose (wav->f);
+    g_free (wav);
+    return -1;
 }