Created
August 21, 2012 00:39
-
-
Save rdp/3409972 to your computer and use it in GitHub Desktop.
add some c interface COM style stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c | |
index ea6c21c..7694f05 100644 | |
--- a/libavdevice/dshow.c | |
+++ b/libavdevice/dshow.c | |
@@ -574,6 +574,61 @@ dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum, | |
return 0; | |
} | |
+void SetAudioLatency(IPin *AudioCapturePin, int BufferSizeMilliSeconds); | |
+void SetAudioLatency(IPin *AudioCapturePin, int BufferSizeMilliSeconds) | |
+{ | |
+ assert(AudioCapturePin); | |
+ assert(BufferSizeMilliSeconds > 0); | |
+ | |
+ // Get the interfaces we need. | |
+ IAMStreamConfig *config = NULL; | |
+ if (IPin_QueryInterface(AudioCapturePin, &IID_IAMStreamConfig, (void **) &config) != S_OK) { | |
+ av_log(NULL, AV_LOG_ERROR, "fail 1"); | |
+ return; | |
+ } | |
+ | |
+ IAMBufferNegotiation *bufneg = NULL; | |
+ | |
+ if (IPin_QueryInterface(AudioCapturePin, &IID_IAMBufferNegotiation, (void **) &bufneg) != S_OK) { | |
+ av_log(NULL, AV_LOG_ERROR, "fail 2"); | |
+ | |
+ goto end2; | |
+ } | |
+ | |
+ // Get the current audio capture properties. | |
+ AM_MEDIA_TYPE *mt; | |
+ HRESULT hr = IAMStreamConfig_GetFormat(config, &mt); | |
+ if (FAILED(hr)) { | |
+ av_log(NULL, AV_LOG_ERROR, "fail 3"); | |
+ goto end1; | |
+ } | |
+ | |
+ assert(*mt->FormatType() == FORMAT_WaveFormatEx); | |
+ assert(mt->FormatLength() >= sizeof(WAVEFORMATEX)); | |
+ WAVEFORMATEX *wf = (WAVEFORMATEX *)mt->pbFormat; | |
+ | |
+ // Set the desired buffer size. | |
+ ALLOCATOR_PROPERTIES props; | |
+ props.cBuffers = -1; | |
+ props.cbBuffer = wf->nAvgBytesPerSec * BufferSizeMilliSeconds/1000; | |
+ props.cbAlign = -1; | |
+ props.cbPrefix = -1; | |
+ | |
+ HRESULT got = IAMBufferNegotiation_SuggestAllocatorProperties(bufneg, &props); | |
+ if (got != S_OK) | |
+ av_log(NULL, AV_LOG_ERROR, "unable to set smaller audio buffer, got %d", got); | |
+ else | |
+ av_log(NULL, AV_LOG_ERROR, "set audio buffer to %dms", BufferSizeMilliSeconds); | |
+ | |
+ // cleanup | |
+ // TODO FreeMediaType(*mt); | |
+ CoTaskMemFree((void *) mt->pbFormat); | |
+ CoTaskMemFree(mt); | |
+end1: | |
+ IAMBufferNegotiation_Release(bufneg); | |
+end2: | |
+ IAMStreamConfig_Release(config); | |
+} | |
static int | |
dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, | |
@@ -616,6 +671,9 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, | |
} | |
ctx->capture_filter[devtype] = capture_filter; | |
+ if (devtype == 1) | |
+ SetAudioLatency((IPin *) device_pin, 50); | |
+ | |
r = IGraphBuilder_AddFilter(graph, (IBaseFilter *) capture_filter, | |
filter_name[devtype]); | |
if (r != S_OK) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment