From patchwork Tue Sep 20 13:16:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 115530 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B2C31B708F for ; Tue, 20 Sep 2011 23:17:07 +1000 (EST) Received: from localhost ([::1]:36499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R60C7-0003QC-QG for incoming@patchwork.ozlabs.org; Tue, 20 Sep 2011 09:17:03 -0400 Received: from eggs.gnu.org ([140.186.70.92]:35952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R60Bu-0003FH-OR for qemu-devel@nongnu.org; Tue, 20 Sep 2011 09:16:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R60Bo-0003A1-Sa for qemu-devel@nongnu.org; Tue, 20 Sep 2011 09:16:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62625) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R60Bo-00039b-Gz for qemu-devel@nongnu.org; Tue, 20 Sep 2011 09:16:44 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p8KDGevR015041 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 20 Sep 2011 09:16:41 -0400 Received: from trasno.mitica (ovpn-113-56.phx2.redhat.com [10.3.113.56]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p8KDGZeu028251; Tue, 20 Sep 2011 09:16:39 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Tue, 20 Sep 2011 15:16:28 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/3] wavcapture: Use stdio instead of QEMUFile X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 CC: malc --- audio/wavcapture.c | 48 ++++++++++++++++++++++++++++++++++-------------- 1 files changed, 34 insertions(+), 14 deletions(-) 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; }