From: Andoni Morales Alastruey Date: Tue, 11 Jun 2013 09:54:41 +0000 (+0200) Subject: dshowaudiosrc: fix audiocapture producing silence X-Git-Tag: 1.19.3~507^2~13405 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c450a15f9f298d3d694ddcc4b6cd359e4d09b8cd;p=platform%2Fupstream%2Fgstreamer.git dshowaudiosrc: fix audiocapture producing silence Configure the capture latency using the IAMBufferNegotiation interface and try to respect the configured latency-time and buffer-time --- diff --git a/sys/dshowsrcwrapper/gstdshow.cpp b/sys/dshowsrcwrapper/gstdshow.cpp index 25a3f5d..4f59105 100644 --- a/sys/dshowsrcwrapper/gstdshow.cpp +++ b/sys/dshowsrcwrapper/gstdshow.cpp @@ -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); +} diff --git a/sys/dshowsrcwrapper/gstdshow.h b/sys/dshowsrcwrapper/gstdshow.h index a3e0c1a..92220b6 100644 --- a/sys/dshowsrcwrapper/gstdshow.h +++ b/sys/dshowsrcwrapper/gstdshow.h @@ -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_ */ diff --git a/sys/dshowsrcwrapper/gstdshowaudiosrc.cpp b/sys/dshowsrcwrapper/gstdshowaudiosrc.cpp index 49b5b04..1a816aa 100644 --- a/sys/dshowsrcwrapper/gstdshowaudiosrc.cpp +++ b/sys/dshowsrcwrapper/gstdshowaudiosrc.cpp @@ -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; } }