Bug 679261 - sa_stream_get_min_write should return a result in bytes, not frames. r=cpearce
authorMatthew Gregan <kinetik@flim.org>
Tue, 16 Aug 2011 15:47:45 +1200
changeset 75929 5a4ca4d59be491a1d8d68ee9ad9c40243682885b
parent 75928 c54c3b67c10288c7ef0013a6cb17340cb9fe20cd
child 75930 8813fd93ef5d8d204cd58c13de1ab7cf3f67452c
push id387
push userbzbarsky@mozilla.com
push dateTue, 27 Sep 2011 17:43:12 +0000
treeherdermozilla-aurora@ec885a01be07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs679261
milestone9.0a1
Bug 679261 - sa_stream_get_min_write should return a result in bytes, not frames. r=cpearce
content/media/nsAudioStream.cpp
content/media/nsBuiltinDecoderStateMachine.cpp
media/libsydneyaudio/include/sydney_audio.h
media/libsydneyaudio/src/sydney_audio_aix.c
media/libsydneyaudio/src/sydney_audio_alsa.c
media/libsydneyaudio/src/sydney_audio_android.c
media/libsydneyaudio/src/sydney_audio_mac.c
media/libsydneyaudio/src/sydney_audio_os2.c
media/libsydneyaudio/src/sydney_audio_oss.c
media/libsydneyaudio/src/sydney_audio_pulseaudio.c
media/libsydneyaudio/src/sydney_audio_sunaudio.c
media/libsydneyaudio/src/sydney_audio_waveapi.c
--- a/content/media/nsAudioStream.cpp
+++ b/content/media/nsAudioStream.cpp
@@ -597,25 +597,25 @@ PRInt64 nsAudioStreamLocal::GetSampleOff
 
 PRBool nsAudioStreamLocal::IsPaused()
 {
   return mPaused;
 }
 
 PRInt32 nsAudioStreamLocal::GetMinWriteSamples()
 {
-  size_t samples;
+  size_t size;
   int r = sa_stream_get_min_write(static_cast<sa_stream_t*>(mAudioHandle),
-                                  &samples);
-  if (r == SA_ERROR_NOT_SUPPORTED)
+                                  &size);
+  if (r == SA_ERROR_NOT_SUPPORTED) {
     return 1;
-  else if (r != SA_SUCCESS || samples > PR_INT32_MAX)
+  } else if (r != SA_SUCCESS) {
     return -1;
-
-  return static_cast<PRInt32>(samples);
+  }
+  return static_cast<PRInt32>(size / mChannels / sizeof(short));
 }
 
 nsAudioStreamRemote::nsAudioStreamRemote()
  : mAudioChild(NULL),
    mFormat(FORMAT_S16_LE),
    mRate(0),
    mChannels(0),
    mBytesPerSample(1),
--- a/content/media/nsBuiltinDecoderStateMachine.cpp
+++ b/content/media/nsBuiltinDecoderStateMachine.cpp
@@ -666,17 +666,17 @@ void nsBuiltinDecoderStateMachine::Audio
         // samples written to start playback.
         PRInt64 samples = minWriteSamples - samplesWritten;
         if (samples < PR_UINT32_MAX / channels) {
           // Write silence manually rather than using PlaySilence(), so that
           // the AudioAPI doesn't get a copy of the samples.
           PRUint32 numValues = samples * channels;
           nsAutoArrayPtr<SoundDataValue> buf(new SoundDataValue[numValues]);
           memset(buf.get(), 0, sizeof(SoundDataValue) * numValues);
-          mAudioStream->Write(buf, numValues, PR_TRUE);
+          mAudioStream->Write(buf, numValues);
         }
       }
 
       PRInt64 oldPosition = -1;
       PRInt64 position = GetMediaTime();
       while (oldPosition != position &&
              mAudioEndTime - position > 0 &&
              mState != DECODER_STATE_SEEKING &&
--- a/media/libsydneyaudio/include/sydney_audio.h
+++ b/media/libsydneyaudio/include/sydney_audio.h
@@ -447,17 +447,17 @@ int sa_stream_resume(sa_stream_t *s);
 /** Pause audio playback (do not empty the buffer) */
 int sa_stream_pause(sa_stream_t *s);
 
 /** Block until all audio has been played */
 int sa_stream_drain(sa_stream_t *s);
 
 /** Returns the minimum number of bytes which must be written before any
     audio is played by the hardware. */
-int sa_stream_get_min_write(sa_stream_t *s, size_t *samples);
+int sa_stream_get_min_write(sa_stream_t *s, size_t *size);
 
 /** Return a human readable error */
 const char *sa_strerror(int code);
 
 /* Extensions */
 int
 sa_stream_set_volume_abs(sa_stream_t *s, float vol);
 
--- a/media/libsydneyaudio/src/sydney_audio_aix.c
+++ b/media/libsydneyaudio/src/sydney_audio_aix.c
@@ -474,12 +474,12 @@ UNSUPPORTED(int sa_stream_get_event_erro
 UNSUPPORTED(int sa_stream_get_event_notify(sa_stream_t *s, sa_notify_t *notify))
 UNSUPPORTED(int sa_stream_read(sa_stream_t *s, void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_read_ni(sa_stream_t *s, unsigned int channel, void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_write_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_pwrite(sa_stream_t *s, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
 UNSUPPORTED(int sa_stream_pwrite_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
 UNSUPPORTED(int sa_stream_get_read_size(sa_stream_t *s, size_t *size))
 UNSUPPORTED(int sa_stream_drain(sa_stream_t *s))
-UNSUPPORTED(int sa_stream_get_min_write(sa_stream_t *s, size_t *samples))
+UNSUPPORTED(int sa_stream_get_min_write(sa_stream_t *s, size_t *size))
 
 const char *sa_strerror(int code) { return NULL; }
 
--- a/media/libsydneyaudio/src/sydney_audio_alsa.c
+++ b/media/libsydneyaudio/src/sydney_audio_alsa.c
@@ -185,29 +185,30 @@ sa_stream_open(sa_stream_t *s) {
 
   pthread_mutex_unlock(&sa_alsa_mutex);
 
   return SA_SUCCESS;
 }
 
 
 int
-sa_stream_get_min_write(sa_stream_t *s, size_t *samples) {
+sa_stream_get_min_write(sa_stream_t *s, size_t *size) {
   int r;
   snd_pcm_uframes_t threshold;
   snd_pcm_sw_params_t* swparams;
   if (s == NULL || s->output_unit == NULL) {
     return SA_ERROR_NO_INIT;
   }
   snd_pcm_sw_params_alloca(&swparams);
   snd_pcm_sw_params_current(s->output_unit, swparams);
   r = snd_pcm_sw_params_get_start_threshold(swparams, &threshold);
-  if (r < 0)
+  if (r < 0) {
     return SA_ERROR_NO_INIT;
-  *samples = threshold;
+  }
+  *size = snd_pcm_frames_to_bytes(s->output_unit, threshold);
 
   return SA_SUCCESS;
 }
 
 
 int
 sa_stream_destroy(sa_stream_t *s) {
   int result = SA_SUCCESS;
--- a/media/libsydneyaudio/src/sydney_audio_android.c
+++ b/media/libsydneyaudio/src/sydney_audio_android.c
@@ -529,12 +529,12 @@ UNSUPPORTED(int sa_stream_get_event_erro
 UNSUPPORTED(int sa_stream_get_event_notify(sa_stream_t *s, sa_notify_t *notify))
 UNSUPPORTED(int sa_stream_read(sa_stream_t *s, void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_read_ni(sa_stream_t *s, unsigned int channel, void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_write_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_pwrite(sa_stream_t *s, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
 UNSUPPORTED(int sa_stream_pwrite_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
 UNSUPPORTED(int sa_stream_get_read_size(sa_stream_t *s, size_t *size))
 UNSUPPORTED(int sa_stream_get_volume_abs(sa_stream_t *s, float *vol))
-UNSUPPORTED(int sa_stream_get_min_write(sa_stream_t *s, size_t *samples))
+UNSUPPORTED(int sa_stream_get_min_write(sa_stream_t *s, size_t *size))
 
 const char *sa_strerror(int code) { return NULL; }
 
--- a/media/libsydneyaudio/src/sydney_audio_mac.c
+++ b/media/libsydneyaudio/src/sydney_audio_mac.c
@@ -727,12 +727,12 @@ UNSUPPORTED(int sa_stream_get_state(sa_s
 UNSUPPORTED(int sa_stream_get_event_error(sa_stream_t *s, sa_error_t *error))
 UNSUPPORTED(int sa_stream_get_event_notify(sa_stream_t *s, sa_notify_t *notify))
 UNSUPPORTED(int sa_stream_read(sa_stream_t *s, void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_read_ni(sa_stream_t *s, unsigned int channel, void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_write_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_pwrite(sa_stream_t *s, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
 UNSUPPORTED(int sa_stream_pwrite_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
 UNSUPPORTED(int sa_stream_get_read_size(sa_stream_t *s, size_t *size))
-UNSUPPORTED(int sa_stream_get_min_write(sa_stream_t *s, size_t *samples))
+UNSUPPORTED(int sa_stream_get_min_write(sa_stream_t *s, size_t *size))
 
 const char *sa_strerror(int code) { return NULL; }
 
--- a/media/libsydneyaudio/src/sydney_audio_os2.c
+++ b/media/libsydneyaudio/src/sydney_audio_os2.c
@@ -923,14 +923,14 @@ UNSUPPORTED(int sa_stream_get_state(sa_s
 UNSUPPORTED(int sa_stream_get_event_error(sa_stream_t *s, sa_error_t *error))
 UNSUPPORTED(int sa_stream_get_event_notify(sa_stream_t *s, sa_notify_t *notify))
 UNSUPPORTED(int sa_stream_read(sa_stream_t *s, void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_read_ni(sa_stream_t *s, unsigned int channel, void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_write_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_pwrite(sa_stream_t *s, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
 UNSUPPORTED(int sa_stream_pwrite_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
 UNSUPPORTED(int sa_stream_get_read_size(sa_stream_t *s, size_t *size))
-UNSUPPORTED(int sa_stream_get_min_write(sa_stream_t *s, size_t *samples))
+UNSUPPORTED(int sa_stream_get_min_write(sa_stream_t *s, size_t *size))
 
 const char *sa_strerror(int code) { return NULL; }
 
 /*****************************************************************************/
 
--- a/media/libsydneyaudio/src/sydney_audio_oss.c
+++ b/media/libsydneyaudio/src/sydney_audio_oss.c
@@ -717,13 +717,13 @@ UNSUPPORTED(int sa_stream_get_event_erro
 UNSUPPORTED(int sa_stream_get_event_notify(sa_stream_t *s, sa_notify_t *notify))
 UNSUPPORTED(int sa_stream_read(sa_stream_t *s, void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_read_ni(sa_stream_t *s, unsigned int channel, void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_write_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_pwrite(sa_stream_t *s, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
 UNSUPPORTED(int sa_stream_pwrite_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
 UNSUPPORTED(int sa_stream_get_read_size(sa_stream_t *s, size_t *size))
 UNSUPPORTED(int sa_stream_drain(sa_stream_t *s))
-UNSUPPORTED(int sa_stream_get_min_write(sa_stream_t *s, size_t *samples))
+UNSUPPORTED(int sa_stream_get_min_write(sa_stream_t *s, size_t *size))
 
 const char *sa_strerror(int code) { return NULL; }
 
 #endif
--- a/media/libsydneyaudio/src/sydney_audio_pulseaudio.c
+++ b/media/libsydneyaudio/src/sydney_audio_pulseaudio.c
@@ -697,12 +697,12 @@ UNSUPPORTED(int sa_stream_get_event_erro
 UNSUPPORTED(int sa_stream_get_event_notify(sa_stream_t *s, sa_notify_t *notify))
 UNSUPPORTED(int sa_stream_read(sa_stream_t *s, void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_read_ni(sa_stream_t *s, unsigned int channel, void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_write_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_pwrite(sa_stream_t *s, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
 UNSUPPORTED(int sa_stream_pwrite_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
 UNSUPPORTED(int sa_stream_get_read_size(sa_stream_t *s, size_t *size))
 UNSUPPORTED(int sa_stream_drain(sa_stream_t *s))
-UNSUPPORTED(int sa_stream_get_min_write(sa_stream_t *s, size_t *samples))
+UNSUPPORTED(int sa_stream_get_min_write(sa_stream_t *s, size_t *size))
 
 const char *sa_strerror(int code) { return NULL; }
 
--- a/media/libsydneyaudio/src/sydney_audio_sunaudio.c
+++ b/media/libsydneyaudio/src/sydney_audio_sunaudio.c
@@ -745,12 +745,12 @@ UNSUPPORTED(int sa_stream_get_state(sa_s
 UNSUPPORTED(int sa_stream_get_event_error(sa_stream_t *s, sa_error_t *error))
 UNSUPPORTED(int sa_stream_get_event_notify(sa_stream_t *s, sa_notify_t *notify))
 UNSUPPORTED(int sa_stream_read(sa_stream_t *s, void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_read_ni(sa_stream_t *s, unsigned int channel, void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_write_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes))
 UNSUPPORTED(int sa_stream_pwrite(sa_stream_t *s, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
 UNSUPPORTED(int sa_stream_pwrite_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
 UNSUPPORTED(int sa_stream_get_read_size(sa_stream_t *s, size_t *size))
-UNSUPPORTED(int sa_stream_get_min_write(sa_stream_t *s, size_t *samples))
+UNSUPPORTED(int sa_stream_get_min_write(sa_stream_t *s, size_t *size))
 
 const char *sa_strerror(int code) { return NULL; }
 
--- a/media/libsydneyaudio/src/sydney_audio_waveapi.c
+++ b/media/libsydneyaudio/src/sydney_audio_waveapi.c
@@ -189,19 +189,19 @@ int sa_stream_open(sa_stream_t *s) {
       break;
 	default:
       status = SA_ERROR_NOT_SUPPORTED;      
       break;
   }    
   return status;
 }
 
-int sa_stream_get_min_write(sa_stream_t *s, size_t *samples) {
+int sa_stream_get_min_write(sa_stream_t *s, size_t *size) {
   ERROR_IF_NO_INIT(s);
-  *samples = (s->blockSize / BYTES_PER_SAMPLE) / s->channels;
+  *size = s->blockSize;
   return SA_SUCCESS;
 }
 
 /** Interleaved playback function */
 int sa_stream_write(sa_stream_t *s, const void *data, size_t nbytes) {
   int status = SA_SUCCESS;
 
   ERROR_IF_NO_INIT(s);