mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 18:21:04 +00:00
dshowaudiosrc: fix audiocapture producing silence
Configure the capture latency using the IAMBufferNegotiation interface and try to respect the configured latency-time and buffer-time
This commit is contained in:
parent
d50625eeb0
commit
c450a15f9f
3 changed files with 35 additions and 3 deletions
|
@ -496,3 +496,21 @@ gst_dshow_new_video_caps (GstVideoFormat video_format, const gchar * name,
|
|||
|
||||
return video_caps;
|
||||
}
|
||||
|
||||
bool gst_dshow_configure_latency (IPin *pCapturePin, guint bufSizeMS)
|
||||
{
|
||||
HRESULT hr;
|
||||
ALLOCATOR_PROPERTIES alloc_prop;
|
||||
IAMBufferNegotiation * pNeg = NULL;
|
||||
hr = pCapturePin->QueryInterface(IID_IAMBufferNegotiation, (void **)&pNeg);
|
||||
|
||||
if(!SUCCEEDED (hr))
|
||||
return FALSE;
|
||||
|
||||
alloc_prop.cbAlign = -1; // -1 means no preference.
|
||||
alloc_prop.cbBuffer = bufSizeMS;
|
||||
alloc_prop.cbPrefix = -1;
|
||||
alloc_prop.cBuffers = -1;
|
||||
hr = pNeg->SuggestAllocatorProperties (&alloc_prop);
|
||||
return SUCCEEDED (hr);
|
||||
}
|
||||
|
|
|
@ -96,4 +96,7 @@ GstVideoFormat gst_dshow_guid_to_gst_video_format (AM_MEDIA_TYPE *mediatype);
|
|||
GstCaps *gst_dshow_new_video_caps (GstVideoFormat video_format,
|
||||
const gchar * name, GstCapturePinMediaType * pin_mediatype);
|
||||
|
||||
/* configure the latency of the capture source */
|
||||
bool gst_dshow_configure_latency (IPin *pCapturePin, guint bufSizeMS);
|
||||
|
||||
#endif /* _GSTDSHOW_ */
|
||||
|
|
|
@ -626,6 +626,18 @@ gst_dshowaudiosrc_prepare (GstAudioSrc * asrc, GstRingBufferSpec * spec)
|
|||
goto error;
|
||||
}
|
||||
|
||||
spec->segsize = (gint) (spec->bytes_per_sample * spec->rate * spec->latency_time /
|
||||
GST_MSECOND);
|
||||
spec->segtotal = (gint) ((gfloat) spec->buffer_time /
|
||||
(gfloat) spec->latency_time + 0.5);
|
||||
if (!gst_dshow_configure_latency (pin_mediatype->capture_pin,
|
||||
spec->segsize))
|
||||
{
|
||||
GST_WARNING ("Could not change capture latency");
|
||||
spec->segsize = spec->rate * spec->channels;
|
||||
spec->segtotal = 2;
|
||||
};
|
||||
GST_INFO ("Configuring with segsize:%d segtotal:%d", spec->segsize, spec->segtotal);
|
||||
hres = src->filter_graph->ConnectDirect (pin_mediatype->capture_pin,
|
||||
input_pin, NULL);
|
||||
input_pin->Release ();
|
||||
|
@ -637,8 +649,6 @@ gst_dshowaudiosrc_prepare (GstAudioSrc * asrc, GstRingBufferSpec * spec)
|
|||
goto error;
|
||||
}
|
||||
|
||||
spec->segsize = spec->rate * spec->channels;
|
||||
spec->segtotal = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -720,7 +730,8 @@ gst_dshowaudiosrc_read (GstAudioSrc * asrc, gpointer data, guint length)
|
|||
g_mutex_unlock (src->gbarray_lock);
|
||||
} else {
|
||||
if (src->is_running) {
|
||||
Sleep (100);
|
||||
Sleep (GST_BASE_AUDIO_SRC(src)->ringbuffer->spec.latency_time /
|
||||
GST_MSECOND / 10);
|
||||
goto test;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue