Bug 1432779 - P12. User proper sample size when calculating offsets. r?padenot draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 15 Mar 2018 01:03:54 +0100
changeset 768209 cdd5ee6e882c512f4d30ef296124c9fc38b65ff3
parent 768208 65cd9e6674430b3ddaa32688357b63ed15142d39
child 768210 a996321bbc2b4aac49dfa539207efc5a50f8f5f7
push id102819
push userbmo:jyavenard@mozilla.com
push dateThu, 15 Mar 2018 19:46:59 +0000
reviewerspadenot
bugs1432779
milestone61.0a1
Bug 1432779 - P12. User proper sample size when calculating offsets. r?padenot Should the user data be of a different types to what the AudioUnit output is set to, we would have written outside the end of our allocated buffer. MozReview-Commit-ID: 4oLTyHmm6OZ
media/libcubeb/src/cubeb_audiounit.cpp
--- a/media/libcubeb/src/cubeb_audiounit.cpp
+++ b/media/libcubeb/src/cubeb_audiounit.cpp
@@ -593,28 +593,28 @@ audiounit_output_callback(void * user_pt
       r = AudioOutputUnitStop(stm->input_unit);
       assert(r == 0);
     }
     stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_ERROR);
     audiounit_make_silent(&outBufferList->mBuffers[0]);
     return noErr;
   }
 
-  size_t outbpf = stm->output_desc.mBytesPerFrame;
   stm->draining = (UInt32) outframes < output_frames;
   stm->frames_played = stm->frames_queued;
   stm->frames_queued += outframes;
 
   AudioFormatFlags outaff = stm->output_desc.mFormatFlags;
   float panning = (stm->output_desc.mChannelsPerFrame == 2) ?
       stm->panning.load(memory_order_relaxed) : 0.0f;
 
   /* Post process output samples. */
   if (stm->draining) {
     /* Clear missing frames (silence) */
+    size_t outbpf = cubeb_sample_size(stm->output_stream_params.format);
     memset((uint8_t*)output_buffer + outframes * outbpf, 0, (output_frames - outframes) * outbpf);
     // JYA TODO : shouldn't output_frames be reduced here for the remaining panning/remix operation?
   }
 
   /* Mixing */
   if (stm->mixer) {
     audiounit_mix_output_buffer(stm,
                                 output_frames,