[xiph-commits] r3698 - in browser_plugin/trunk: . src/audio

j at svn.annodex.net j at svn.annodex.net
Fri Aug 8 13:02:04 PDT 2008


Author: j
Date: 2008-08-08 13:02:04 -0700 (Fri, 08 Aug 2008)
New Revision: 3698

Modified:
   browser_plugin/trunk/configure.ac
   browser_plugin/trunk/src/audio/sydney_audio_oss.c
   browser_plugin/trunk/src/audio/sydney_audio_pulseaudio.c
Log:
 * new configure option (--with-alsa) to not use pulseaudio if found
 * no need to set buffer data to 0 but write less data (oss and pulse)
 * implement sa_stream_get_position in oss backend



Modified: browser_plugin/trunk/configure.ac
===================================================================
--- browser_plugin/trunk/configure.ac	2008-08-08 19:35:04 UTC (rev 3697)
+++ browser_plugin/trunk/configure.ac	2008-08-08 20:02:04 UTC (rev 3698)
@@ -70,7 +70,22 @@
 AC_SUBST(PULSE_CFLAGS)
 AC_SUBST(PULSE_LIBS)
 
+dnl
+dnl  alsa backend configure option
+dnl
+AC_ARG_WITH(alsa,
+[  --with-alsa   Use ALSA audio backend],
+[ case "$withval" in
+  no)
+    ;;
+  *)
+    HAVE_ALSA=yes
+    HAVE_PULSE=no
+    ;;
+  esac]
+)
 
+
 dnl
 dnl  oss backend configure option
 dnl

Modified: browser_plugin/trunk/src/audio/sydney_audio_oss.c
===================================================================
--- browser_plugin/trunk/src/audio/sydney_audio_oss.c	2008-08-08 19:35:04 UTC (rev 3697)
+++ browser_plugin/trunk/src/audio/sydney_audio_oss.c	2008-08-08 20:02:04 UTC (rev 3698)
@@ -424,6 +424,7 @@
   while(1) {
     char* dst = buffer;
     unsigned int bytes_to_copy = info.bytes;
+    int bytes = info.bytes;
 
     pthread_mutex_lock(&s->mutex);
     if (!s->thread_id)
@@ -460,14 +461,14 @@
         /*
          * We want to free the now-empty buffer, but not if it's also the
          * current tail. If it is the tail, we don't have enough data to fill
-         * the destination buffer, so we'll just zero it out and give up.
+         * the destination buffer, so we write less and give up.
          */
         next = s->bl_head->next;
         if (next == NULL) {
 #ifdef TIMING_TRACE
           printf("!");  /* not enough audio data */
 #endif
-          memset(dst, 0, bytes_to_copy);
+          bytes = bytes-bytes_to_copy;
           break;
         }
         free(s->bl_head);
@@ -480,13 +481,15 @@
 
     pthread_mutex_unlock(&s->mutex);
 
-    frames = write(s->output_fd, buffer, info.bytes);
-    if (frames < 0) {
-        printf("error writing to sound device\n");
+    if(bytes > 0) {
+      frames = write(s->output_fd, buffer, bytes);
+      if (frames < 0) {
+          printf("error writing to sound device\n");
+      }
+      if (frames >= 0 && frames != bytes) {
+         printf("short write (expected %d, wrote %d)\n", (int)bytes, (int)frames);
+      }
     }
-    if (frames >= 0 && frames != info.bytes) {
-       printf("short write (expected %d, wrote %d)\n", (int)info.bytes, (int)frames);
-    }
   }
   free(buffer);
 }
@@ -526,6 +529,8 @@
 
 int
 sa_stream_get_position(sa_stream_t *s, sa_position_t position, int64_t *pos) {
+   int err;
+   count_info ptr;
 
   if (s == NULL || s->output_unit == NULL) {
     return SA_ERROR_NO_INIT;
@@ -533,9 +538,15 @@
   if (position != SA_POSITION_WRITE_SOFTWARE) {
     return SA_ERROR_NOT_SUPPORTED;
   }
+  if ((err = ioctl(s->output_fd, 
+                       SNDCTL_DSP_GETOPTR, 
+                       &ptr)) <0) {
+      fprintf(stderr, "Error reading playback position\n");
+      return SA_ERROR_OOM;
+  }
 
   pthread_mutex_lock(&s->mutex);
-  *pos = s->bytes_played;
+  *pos = (int64_t)ptr.bytes;
   pthread_mutex_unlock(&s->mutex);
   return SA_SUCCESS;
 }

Modified: browser_plugin/trunk/src/audio/sydney_audio_pulseaudio.c
===================================================================
--- browser_plugin/trunk/src/audio/sydney_audio_pulseaudio.c	2008-08-08 19:35:04 UTC (rev 3697)
+++ browser_plugin/trunk/src/audio/sydney_audio_pulseaudio.c	2008-08-08 20:02:04 UTC (rev 3698)
@@ -364,11 +364,10 @@
         /*
          * We want to free the now-empty buffer, but not if it's also the
          * current tail. If it is the tail, we don't have enough data to fill
-         * the destination buffer, so we'll just zero it out and give up.
+         * the destination buffer, so we write less and give up.
          */
         next = s->bl_head->next;
         if (next == NULL) {
-          memset(dst, 0, bytes_to_copy);
           bytes = bytes-bytes_to_copy;
           break;
         }



More information about the commits mailing list