diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2017-04-06 16:13:41 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2017-04-06 16:15:28 +0300 |
commit | 6d256d9908e292f6c593bf45e69354f6b613cc8b (patch) | |
tree | 04e6ef2f928b52e97ba3dab955b0dc58b8445cf7 | |
parent | 58370ed6cf733380024fad3eb39334d06cfc7534 (diff) |
directsoundsrc: Correctly calculate segsize and segtotal
segsize should be based on latency-time, and must be a multiple of the
frame size. segtotal should be based on buffer-time and segsize.
This prevents errors caused by outputting buffers that are not a
multiple of the frame size, and actually makes the buffer-time and
latency-time properties do what they're supposed to do.
-rw-r--r-- | sys/directsound/gstdirectsoundsrc.c | 32 | ||||
-rw-r--r-- | sys/directsound/gstdirectsoundsrc.h | 2 |
2 files changed, 15 insertions, 19 deletions
diff --git a/sys/directsound/gstdirectsoundsrc.c b/sys/directsound/gstdirectsoundsrc.c index 397746641..3bb62fdcd 100644 --- a/sys/directsound/gstdirectsoundsrc.c +++ b/sys/directsound/gstdirectsoundsrc.c @@ -564,22 +564,20 @@ gst_directsound_src_prepare (GstAudioSrc * asrc, GstAudioRingBufferSpec * spec) GST_WARNING ("buffer-time was less than latency"); } - /* Save the times */ - dsoundsrc->buffer_time = spec->buffer_time; - dsoundsrc->latency_time = spec->latency_time; - - dsoundsrc->latency_size = (gint) wfx.nAvgBytesPerSec * - dsoundsrc->latency_time / 1000000.0; - - spec->segsize = (guint) (((double) spec->buffer_time / 1000000.0) * - wfx.nAvgBytesPerSec); - - /* just in case */ - if (spec->segsize < 1) - spec->segsize = 1; - - spec->segtotal = GST_AUDIO_INFO_BPF (&spec->info) * 8 * - (wfx.nAvgBytesPerSec / spec->segsize); + spec->segsize = + gst_util_uint64_scale (spec->latency_time, wfx.nAvgBytesPerSec, 1000000); + if (spec->segsize < GST_AUDIO_INFO_BPF (&spec->info)) + spec->segsize = GST_AUDIO_INFO_BPF (&spec->info); + else if (spec->segsize % GST_AUDIO_INFO_BPF (&spec->info) != 0) + spec->segsize = + ((spec->segsize + GST_AUDIO_INFO_BPF (&spec->info) - + 1) / GST_AUDIO_INFO_BPF (&spec->info)) * + GST_AUDIO_INFO_BPF (&spec->info); + + dsoundsrc->latency_time = + gst_util_uint64_scale (spec->segsize, 1000000, + GST_AUDIO_INFO_BPF (&spec->info) * GST_AUDIO_INFO_RATE (&spec->info)); + spec->segtotal = spec->buffer_time / dsoundsrc->latency_time; GST_DEBUG_OBJECT (asrc, "bytes/sec: %lu, buffer size: %d, segsize: %d, segtotal: %d", @@ -818,7 +816,7 @@ gst_directsound_src_mixer_find (GstDirectSoundSrc * dsoundsrc, if (mmres != MMSYSERR_NOERROR) continue; - mmres = mixerGetDevCaps ((UINT_PTR)dsoundsrc->mixer, + mmres = mixerGetDevCaps ((UINT_PTR) dsoundsrc->mixer, mixer_caps, sizeof (MIXERCAPS)); if (mmres != MMSYSERR_NOERROR) { diff --git a/sys/directsound/gstdirectsoundsrc.h b/sys/directsound/gstdirectsoundsrc.h index 9aa225fb3..31218976d 100644 --- a/sys/directsound/gstdirectsoundsrc.h +++ b/sys/directsound/gstdirectsoundsrc.h @@ -86,10 +86,8 @@ struct _GstDirectSoundSrc DWORD notifysize; guint buffer_size; - guint latency_size; guint bytes_per_sample; - guint buffer_time; guint latency_time; HMIXER mixer; |