HRESULT WINAPI QualityControlImpl_Notify(IQualityControl *iface, IBaseFilter *sender, Quality qm) { QualityControlImpl *This = impl_from_IQualityControl(iface); HRESULT hr = S_FALSE; TRACE("%p %p { 0x%x %u " XTIME_FMT " " XTIME_FMT " }\n", This, sender, qm.Type, qm.Proportion, XTIME(qm.Late), XTIME(qm.TimeStamp)); if (This->tonotify) return IQualityControl_Notify(This->tonotify, This->self, qm); if (This->input) { IPin *to = NULL; IPin_ConnectedTo(This->input, &to); if (to) { IQualityControl *qc = NULL; IPin_QueryInterface(to, &IID_IQualityControl, (void**)&qc); if (qc) { hr = IQualityControl_Notify(qc, This->self, qm); IQualityControl_Release(qc); } IPin_Release(to); } } return hr; }
HRESULT qcap_driver_stop(Capture *capBox, FILTER_STATE *state) { TRACE("%p -> (%p)\n", capBox, state); if (*state == State_Stopped) return S_OK; EnterCriticalSection(&capBox->CritSect); if (capBox->thread) { if (*state == State_Paused) ResumeThread(capBox->thread); capBox->stopped = 1; capBox->thread = 0; if (capBox->iscommitted) { IMemInputPin *pMem = NULL; IMemAllocator * pAlloc = NULL; IPin *pConnect = NULL; HRESULT hr; capBox->iscommitted = 0; hr = IPin_ConnectedTo(capBox->pOut, &pConnect); if (SUCCEEDED(hr)) hr = IPin_QueryInterface(pConnect, &IID_IMemInputPin, (void **) &pMem); if (SUCCEEDED(hr)) hr = IMemInputPin_GetAllocator(pMem, &pAlloc); if (SUCCEEDED(hr)) hr = IMemAllocator_Decommit(pAlloc); if (pAlloc) IMemAllocator_Release(pAlloc); if (pMem) IMemInputPin_Release(pMem); if (pConnect) IPin_Release(pConnect); if (hr != S_OK && hr != VFW_E_NOT_COMMITTED) WARN("Decommitting allocator: %x\n", hr); } V4l_Unprepare(capBox); } *state = State_Stopped; LeaveCriticalSection(&capBox->CritSect); return S_OK; }
static void test_pin(IPin *pin) { IMemInputPin *mpin = NULL; IPin_QueryInterface(pin, &IID_IMemInputPin, (void **)&mpin); ok(mpin == NULL, "IMemInputPin found!\n"); if (mpin) IMemInputPin_Release(mpin); /* TODO */ }
/** * Set audio device buffer size in milliseconds (which can directly impact * latency, depending on the device). */ static int dshow_set_audio_buffer_size(AVFormatContext *avctx, IPin *pin) { struct dshow_ctx *ctx = avctx->priv_data; IAMBufferNegotiation *buffer_negotiation = NULL; ALLOCATOR_PROPERTIES props = { -1, -1, -1, -1 }; IAMStreamConfig *config = NULL; AM_MEDIA_TYPE *type = NULL; int ret = AVERROR(EIO); if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (void **) &config) != S_OK) goto end; if (IAMStreamConfig_GetFormat(config, &type) != S_OK) goto end; if (!IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) goto end; props.cbBuffer = (((WAVEFORMATEX *) type->pbFormat)->nAvgBytesPerSec) * ctx->audio_buffer_size / 1000; if (IPin_QueryInterface(pin, &IID_IAMBufferNegotiation, (void **) &buffer_negotiation) != S_OK) goto end; if (IAMBufferNegotiation_SuggestAllocatorProperties(buffer_negotiation, &props) != S_OK) goto end; ret = 0; end: if (buffer_negotiation) IAMBufferNegotiation_Release(buffer_negotiation); if (type) { if (type->pbFormat) CoTaskMemFree(type->pbFormat); CoTaskMemFree(type); } if (config) IAMStreamConfig_Release(config); return ret; }
static HRESULT get_connected(PassThruImpl *This, REFIID riid, LPVOID *ppvObj) { HRESULT hr; IPin *pin; *ppvObj = NULL; hr = IPin_ConnectedTo(This->pin, &pin); if (FAILED(hr)) return VFW_E_NOT_CONNECTED; hr = IPin_QueryInterface(pin, riid, ppvObj); IPin_Release(pin); if (FAILED(hr)) hr = E_NOTIMPL; return hr; }
static void test_pin(IPin *pin) { IMemInputPin *mpin = NULL; IPin_QueryInterface(pin, &IID_IMemInputPin, (void **)&mpin); ok(mpin != NULL, "No IMemInputPin found!\n"); if (mpin) { ok(IMemInputPin_ReceiveCanBlock(mpin) == S_OK, "Receive can't block for pin!\n"); ok(IMemInputPin_NotifyAllocator(mpin, NULL, 0) == E_POINTER, "NotifyAllocator likes a NULL pointer argument\n"); IMemInputPin_Release(mpin); } /* TODO */ }
/* IPin - output pin */ static HRESULT WINAPI SampleGrabber_Out_IPin_Connect(IPin *iface, IPin *receiver, const AM_MEDIA_TYPE *type) { SG_Pin *This = impl_from_IPin(iface); HRESULT hr; TRACE("(%p)->(%p, %p)\n", This, receiver, type); if (!receiver) return E_POINTER; if (This->pair) return VFW_E_ALREADY_CONNECTED; if (This->sg->filter.state != State_Stopped) return VFW_E_NOT_STOPPED; if (type) { TRACE("Media type: %s/%s ssize: %u format: %s (%u bytes)\n", debugstr_guid(&type->majortype), debugstr_guid(&type->subtype), type->lSampleSize, debugstr_guid(&type->formattype), type->cbFormat); if (!IsEqualGUID(&This->sg->mtype.majortype,&GUID_NULL) && !IsEqualGUID(&This->sg->mtype.majortype,&type->majortype)) return VFW_E_TYPE_NOT_ACCEPTED; if (!IsEqualGUID(&This->sg->mtype.subtype,&MEDIASUBTYPE_None) && !IsEqualGUID(&This->sg->mtype.subtype,&type->subtype)) return VFW_E_TYPE_NOT_ACCEPTED; if (!IsEqualGUID(&This->sg->mtype.formattype,&GUID_NULL) && !IsEqualGUID(&This->sg->mtype.formattype,&FORMAT_None) && !IsEqualGUID(&This->sg->mtype.formattype,&type->formattype)) return VFW_E_TYPE_NOT_ACCEPTED; } else type = &This->sg->mtype; if (!IsEqualGUID(&type->formattype, &FORMAT_None) && !IsEqualGUID(&type->formattype, &GUID_NULL) && !type->pbFormat) return VFW_E_TYPE_NOT_ACCEPTED; hr = IPin_ReceiveConnection(receiver, &This->IPin_iface, type); if (FAILED(hr)) return hr; This->pair = receiver; if (This->sg->memOutput) { IMemInputPin_Release(This->sg->memOutput); This->sg->memOutput = NULL; } IPin_QueryInterface(receiver,&IID_IMemInputPin,(void **)&(This->sg->memOutput)); TRACE("(%p) Accepted IPin %p, IMemInputPin %p\n", This, receiver, This->sg->memOutput); return S_OK; }
HRESULT WINAPI QualityControlImpl_Notify(IQualityControl *iface, IBaseFilter *sender, Quality qm) { HRESULT hr = S_FALSE; QualityControlImpl *This = (QualityControlImpl*)iface; if (This->tonotify) return IQualityControl_Notify(This->tonotify, This->self, qm); if (This->input) { IPin *to = NULL; IPin_ConnectedTo(This->input, &to); if (to) { IQualityControl *qc = NULL; IPin_QueryInterface(to, &IID_IQualityControl, (void**)&qc); if (qc) { hr = IQualityControl_Notify(qc, This->self, qm); IQualityControl_Release(qc); } IPin_Release(to); } } return hr; }
/** * Cycle through available pins using the device_filter device, of type * devtype, retrieve the first output pin and return the pointer to the * object found in *ppin. * If ppin is NULL, cycle through all pins listing audio/video capabilities. */ static int dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype, IBaseFilter *device_filter, IPin **ppin) { struct dshow_ctx *ctx = avctx->priv_data; IEnumPins *pins = 0; IPin *device_pin = NULL; IPin *pin; int r; const GUID *mediatype[2] = { &MEDIATYPE_Video, &MEDIATYPE_Audio }; const char *devtypename = (devtype == VideoDevice) ? "video" : "audio only"; const char *sourcetypename = (sourcetype == VideoSourceDevice) ? "video" : "audio"; int set_format = (devtype == VideoDevice && (ctx->framerate || (ctx->requested_width && ctx->requested_height) || ctx->pixel_format != AV_PIX_FMT_NONE || ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO)) || (devtype == AudioDevice && (ctx->channels || ctx->sample_rate)); int format_set = 0; int should_show_properties = (devtype == VideoDevice) ? ctx->show_video_device_dialog : ctx->show_audio_device_dialog; if (should_show_properties) dshow_show_filter_properties(device_filter, avctx); r = IBaseFilter_EnumPins(device_filter, &pins); if (r != S_OK) { av_log(avctx, AV_LOG_ERROR, "Could not enumerate pins.\n"); return AVERROR(EIO); } if (!ppin) { av_log(avctx, AV_LOG_INFO, "DirectShow %s device options (from %s devices)\n", devtypename, sourcetypename); } while (!device_pin && IEnumPins_Next(pins, 1, &pin, NULL) == S_OK) { IKsPropertySet *p = NULL; IEnumMediaTypes *types = NULL; PIN_INFO info = {0}; AM_MEDIA_TYPE *type; GUID category; DWORD r2; char *name_buf = NULL; wchar_t *pin_id = NULL; char *pin_buf = NULL; char *desired_pin_name = devtype == VideoDevice ? ctx->video_pin_name : ctx->audio_pin_name; IPin_QueryPinInfo(pin, &info); IBaseFilter_Release(info.pFilter); if (info.dir != PINDIR_OUTPUT) goto next; if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (void **) &p) != S_OK) goto next; if (IKsPropertySet_Get(p, &ROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, NULL, 0, &category, sizeof(GUID), &r2) != S_OK) goto next; if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE)) goto next; name_buf = dup_wchar_to_utf8(info.achName); r = IPin_QueryId(pin, &pin_id); if (r != S_OK) { av_log(avctx, AV_LOG_ERROR, "Could not query pin id\n"); return AVERROR(EIO); } pin_buf = dup_wchar_to_utf8(pin_id); if (!ppin) { av_log(avctx, AV_LOG_INFO, " Pin \"%s\" (alternative pin name \"%s\")\n", name_buf, pin_buf); dshow_cycle_formats(avctx, devtype, pin, NULL); goto next; } if (desired_pin_name) { if(strcmp(name_buf, desired_pin_name) && strcmp(pin_buf, desired_pin_name)) { av_log(avctx, AV_LOG_DEBUG, "skipping pin \"%s\" (\"%s\") != requested \"%s\"\n", name_buf, pin_buf, desired_pin_name); goto next; } } if (set_format) { dshow_cycle_formats(avctx, devtype, pin, &format_set); if (!format_set) { goto next; } } if (devtype == AudioDevice && ctx->audio_buffer_size) { if (dshow_set_audio_buffer_size(avctx, pin) < 0) { av_log(avctx, AV_LOG_ERROR, "unable to set audio buffer size %d to pin, using pin anyway...", ctx->audio_buffer_size); } } if (IPin_EnumMediaTypes(pin, &types) != S_OK) goto next; IEnumMediaTypes_Reset(types); /* in case format_set was not called, just verify the majortype */ while (!device_pin && IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK) { if (IsEqualGUID(&type->majortype, mediatype[devtype])) { device_pin = pin; av_log(avctx, AV_LOG_DEBUG, "Selecting pin %s on %s\n", name_buf, devtypename); goto next; } CoTaskMemFree(type); } next: if (types) IEnumMediaTypes_Release(types); if (p) IKsPropertySet_Release(p); if (device_pin != pin) IPin_Release(pin); av_free(name_buf); av_free(pin_buf); if (pin_id) CoTaskMemFree(pin_id); } IEnumPins_Release(pins); if (ppin) { if (set_format && !format_set) { av_log(avctx, AV_LOG_ERROR, "Could not set %s options\n", devtypename); return AVERROR(EIO); } if (!device_pin) { av_log(avctx, AV_LOG_ERROR, "Could not find output pin from %s capture device.\n", devtypename); return AVERROR(EIO); } *ppin = device_pin; } return 0; }
/** * Cycle through available formats using the specified pin, * try to set parameters specified through AVOptions and if successful * return 1 in *pformat_set. * If pformat_set is NULL, list all pin capabilities. */ static void dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, IPin *pin, int *pformat_set) { struct dshow_ctx *ctx = avctx->priv_data; IAMStreamConfig *config = NULL; AM_MEDIA_TYPE *type = NULL; int format_set = 0; void *caps = NULL; int i, n, size, r; if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (void **) &config) != S_OK) return; if (IAMStreamConfig_GetNumberOfCapabilities(config, &n, &size) != S_OK) goto end; caps = av_malloc(size); if (!caps) goto end; for (i = 0; i < n && !format_set; i++) { r = IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps); if (r != S_OK) goto next; #if DSHOWDEBUG ff_print_AM_MEDIA_TYPE(type); #endif if (devtype == VideoDevice) { VIDEO_STREAM_CONFIG_CAPS *vcaps = caps; BITMAPINFOHEADER *bih; int64_t *fr; const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; #if DSHOWDEBUG ff_print_VIDEO_STREAM_CONFIG_CAPS(vcaps); #endif if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) { VIDEOINFOHEADER *v = (void *) type->pbFormat; fr = &v->AvgTimePerFrame; bih = &v->bmiHeader; } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) { VIDEOINFOHEADER2 *v = (void *) type->pbFormat; fr = &v->AvgTimePerFrame; bih = &v->bmiHeader; } else { goto next; } if (!pformat_set) { enum AVPixelFormat pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount); if (pix_fmt == AV_PIX_FMT_NONE) { enum AVCodecID codec_id = av_codec_get_id(tags, bih->biCompression); AVCodec *codec = avcodec_find_decoder(codec_id); if (codec_id == AV_CODEC_ID_NONE || !codec) { av_log(avctx, AV_LOG_INFO, " unknown compression type 0x%X", (int) bih->biCompression); } else { av_log(avctx, AV_LOG_INFO, " vcodec=%s", codec->name); } } else { av_log(avctx, AV_LOG_INFO, " pixel_format=%s", av_get_pix_fmt_name(pix_fmt)); } av_log(avctx, AV_LOG_INFO, " min s=%ldx%ld fps=%g max s=%ldx%ld fps=%g\n", vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy, 1e7 / vcaps->MaxFrameInterval, vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy, 1e7 / vcaps->MinFrameInterval); continue; } if (ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO) { if (ctx->video_codec_id != av_codec_get_id(tags, bih->biCompression)) goto next; } if (ctx->pixel_format != AV_PIX_FMT_NONE && ctx->pixel_format != dshow_pixfmt(bih->biCompression, bih->biBitCount)) { goto next; } if (ctx->framerate) { int64_t framerate = ((int64_t) ctx->requested_framerate.den*10000000) / ctx->requested_framerate.num; if (framerate > vcaps->MaxFrameInterval || framerate < vcaps->MinFrameInterval) goto next; *fr = framerate; } if (ctx->requested_width && ctx->requested_height) { if (ctx->requested_width > vcaps->MaxOutputSize.cx || ctx->requested_width < vcaps->MinOutputSize.cx || ctx->requested_height > vcaps->MaxOutputSize.cy || ctx->requested_height < vcaps->MinOutputSize.cy) goto next; bih->biWidth = ctx->requested_width; bih->biHeight = ctx->requested_height; } } else { AUDIO_STREAM_CONFIG_CAPS *acaps = caps; WAVEFORMATEX *fx; #if DSHOWDEBUG ff_print_AUDIO_STREAM_CONFIG_CAPS(acaps); #endif if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) { fx = (void *) type->pbFormat; } else { goto next; } if (!pformat_set) { av_log(avctx, AV_LOG_INFO, " min ch=%lu bits=%lu rate=%6lu max ch=%lu bits=%lu rate=%6lu\n", acaps->MinimumChannels, acaps->MinimumBitsPerSample, acaps->MinimumSampleFrequency, acaps->MaximumChannels, acaps->MaximumBitsPerSample, acaps->MaximumSampleFrequency); continue; } if (ctx->sample_rate) { if (ctx->sample_rate > acaps->MaximumSampleFrequency || ctx->sample_rate < acaps->MinimumSampleFrequency) goto next; fx->nSamplesPerSec = ctx->sample_rate; } if (ctx->sample_size) { if (ctx->sample_size > acaps->MaximumBitsPerSample || ctx->sample_size < acaps->MinimumBitsPerSample) goto next; fx->wBitsPerSample = ctx->sample_size; } if (ctx->channels) { if (ctx->channels > acaps->MaximumChannels || ctx->channels < acaps->MinimumChannels) goto next; fx->nChannels = ctx->channels; } } if (IAMStreamConfig_SetFormat(config, type) != S_OK) goto next; format_set = 1; next: if (type->pbFormat) CoTaskMemFree(type->pbFormat); CoTaskMemFree(type); } end: IAMStreamConfig_Release(config); av_free(caps); if (pformat_set) *pformat_set = format_set; }
/** * Cycle through available pins using the device_filter device, of type * devtype, retrieve the first output pin and return the pointer to the * object found in *ppin. * If ppin is NULL, cycle through all pins listing audio/video capabilities. */ static int dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, IBaseFilter *device_filter, IPin **ppin) { struct dshow_ctx *ctx = avctx->priv_data; IEnumPins *pins = 0; IPin *device_pin = NULL; IPin *pin; int r; const GUID *mediatype[2] = { &MEDIATYPE_Video, &MEDIATYPE_Audio }; const char *devtypename = (devtype == VideoDevice) ? "video" : "audio"; int set_format = (devtype == VideoDevice && (ctx->framerate || (ctx->requested_width && ctx->requested_height) || ctx->pixel_format != AV_PIX_FMT_NONE || ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO)) || (devtype == AudioDevice && (ctx->channels || ctx->sample_rate)); int format_set = 0; r = IBaseFilter_EnumPins(device_filter, &pins); if (r != S_OK) { av_log(avctx, AV_LOG_ERROR, "Could not enumerate pins.\n"); return AVERROR(EIO); } if (!ppin) { av_log(avctx, AV_LOG_INFO, "DirectShow %s device options\n", devtypename); } while (!device_pin && IEnumPins_Next(pins, 1, &pin, NULL) == S_OK) { IKsPropertySet *p = NULL; IEnumMediaTypes *types = NULL; PIN_INFO info = {0}; AM_MEDIA_TYPE *type; GUID category; DWORD r2; IPin_QueryPinInfo(pin, &info); IBaseFilter_Release(info.pFilter); if (info.dir != PINDIR_OUTPUT) goto next; if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (void **) &p) != S_OK) goto next; if (IKsPropertySet_Get(p, &ROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, NULL, 0, &category, sizeof(GUID), &r2) != S_OK) goto next; if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE)) goto next; if (!ppin) { char *buf = dup_wchar_to_utf8(info.achName); av_log(avctx, AV_LOG_INFO, " Pin \"%s\"\n", buf); av_free(buf); dshow_cycle_formats(avctx, devtype, pin, NULL); goto next; } if (set_format) { dshow_cycle_formats(avctx, devtype, pin, &format_set); if (!format_set) { goto next; } } if (devtype == AudioDevice && ctx->audio_buffer_size) { if (dshow_set_audio_buffer_size(avctx, pin) < 0) goto next; } if (IPin_EnumMediaTypes(pin, &types) != S_OK) goto next; IEnumMediaTypes_Reset(types); while (!device_pin && IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK) { if (IsEqualGUID(&type->majortype, mediatype[devtype])) { device_pin = pin; goto next; } CoTaskMemFree(type); } next: if (types) IEnumMediaTypes_Release(types); if (p) IKsPropertySet_Release(p); if (device_pin != pin) IPin_Release(pin); } IEnumPins_Release(pins); if (ppin) { if (set_format && !format_set) { av_log(avctx, AV_LOG_ERROR, "Could not set %s options\n", devtypename); return AVERROR(EIO); } if (!device_pin) { av_log(avctx, AV_LOG_ERROR, "Could not find output pin from %s capture device.\n", devtypename); return AVERROR(EIO); } *ppin = device_pin; } return 0; }
static GstCaps * gst_dshowaudiosrc_get_caps (GstBaseSrc * basesrc) { HRESULT hres = S_OK; IBindCtx *lpbc = NULL; IMoniker *audiom = NULL; DWORD dwEaten; GstDshowAudioSrc *src = GST_DSHOWAUDIOSRC (basesrc); gunichar2 *unidevice = NULL; if (src->device) { g_free (src->device); src->device = NULL; } src->device = gst_dshow_getdevice_from_devicename (&CLSID_AudioInputDeviceCategory, &src->device_name); if (!src->device) { GST_CAT_ERROR (dshowaudiosrc_debug, "No audio device found."); return NULL; } unidevice = g_utf8_to_utf16 (src->device, strlen (src->device), NULL, NULL, NULL); if (!src->audio_cap_filter) { hres = CreateBindCtx (0, &lpbc); if (SUCCEEDED (hres)) { hres = MkParseDisplayName (lpbc, unidevice, &dwEaten, &audiom); if (SUCCEEDED (hres)) { hres = IMoniker_BindToObject (audiom, lpbc, NULL, &IID_IBaseFilter, &src->audio_cap_filter); IMoniker_Release (audiom); } IBindCtx_Release (lpbc); } } if (src->audio_cap_filter && !src->caps) { /* get the capture pins supported types */ IPin *capture_pin = NULL; IEnumPins *enumpins = NULL; HRESULT hres; hres = IBaseFilter_EnumPins (src->audio_cap_filter, &enumpins); if (SUCCEEDED (hres)) { while (IEnumPins_Next (enumpins, 1, &capture_pin, NULL) == S_OK) { IKsPropertySet *pKs = NULL; hres = IPin_QueryInterface (capture_pin, &IID_IKsPropertySet, (void **) &pKs); if (SUCCEEDED (hres) && pKs) { DWORD cbReturned; GUID pin_category; RPC_STATUS rpcstatus; hres = IKsPropertySet_Get (pKs, &ROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, NULL, 0, &pin_category, sizeof (GUID), &cbReturned); /* we only want capture pins */ if (UuidCompare (&pin_category, &PIN_CATEGORY_CAPTURE, &rpcstatus) == 0) { IAMStreamConfig *streamcaps = NULL; if (SUCCEEDED (IPin_QueryInterface (capture_pin, &IID_IAMStreamConfig, (void **) &streamcaps))) { src->caps = gst_dshowaudiosrc_getcaps_from_streamcaps (src, capture_pin, streamcaps); IAMStreamConfig_Release (streamcaps); } } IKsPropertySet_Release (pKs); } IPin_Release (capture_pin); } IEnumPins_Release (enumpins); } } if (unidevice) { g_free (unidevice); } if (src->caps) { return gst_caps_ref (src->caps); } return NULL; }
HRESULT WINAPI QT_QualityControl_QueryInterface(IQualityControl *iface, REFIID riid, void **ppv) { QTOutPin *This = impl_from_IQualityControl(iface); return IPin_QueryInterface(&This->pin.pin.IPin_iface, riid, ppv); }
static HRESULT WINAPI QTInPin_ReceiveConnection(IPin *iface, IPin *pReceivePin, const AM_MEDIA_TYPE *pmt) { HRESULT hr = S_OK; ALLOCATOR_PROPERTIES props; QTInPin *This = impl_from_IPin(iface); TRACE("(%p/%p)->(%p, %p)\n", This, iface, pReceivePin, pmt); EnterCriticalSection(This->pin.pCritSec); This->pReader = NULL; if (This->pin.pConnectedTo) hr = VFW_E_ALREADY_CONNECTED; else if (IPin_QueryAccept(iface, pmt) != S_OK) hr = VFW_E_TYPE_NOT_ACCEPTED; else { PIN_DIRECTION pindirReceive; IPin_QueryDirection(pReceivePin, &pindirReceive); if (pindirReceive != PINDIR_OUTPUT) hr = VFW_E_INVALID_DIRECTION; } if (FAILED(hr)) { LeaveCriticalSection(This->pin.pCritSec); return hr; } hr = IPin_QueryInterface(pReceivePin, &IID_IAsyncReader, (LPVOID *)&This->pReader); if (FAILED(hr)) { LeaveCriticalSection(This->pin.pCritSec); TRACE("Input source is not an AsyncReader\n"); return hr; } LeaveCriticalSection(This->pin.pCritSec); EnterCriticalSection(&impl_from_IBaseFilter(This->pin.pinInfo.pFilter)->filter.csFilter); hr = QT_Process_Movie(impl_from_IBaseFilter(This->pin.pinInfo.pFilter)); if (FAILED(hr)) { LeaveCriticalSection(&impl_from_IBaseFilter(This->pin.pinInfo.pFilter)->filter.csFilter); TRACE("Unable to process movie\n"); return hr; } This->pAlloc = NULL; props.cBuffers = 8; props.cbAlign = 1; props.cbBuffer = impl_from_IBaseFilter(This->pin.pinInfo.pFilter)->outputSize + props.cbAlign; props.cbPrefix = 0; hr = IAsyncReader_RequestAllocator(This->pReader, NULL, &props, &This->pAlloc); if (SUCCEEDED(hr)) { CopyMediaType(&This->pin.mtCurrent, pmt); This->pin.pConnectedTo = pReceivePin; IPin_AddRef(pReceivePin); hr = IMemAllocator_Commit(This->pAlloc); } else { QT_RemoveOutputPins(impl_from_IBaseFilter(This->pin.pinInfo.pFilter)); if (This->pReader) IAsyncReader_Release(This->pReader); This->pReader = NULL; if (This->pAlloc) IMemAllocator_Release(This->pAlloc); This->pAlloc = NULL; } TRACE("Size: %i\n", props.cbBuffer); LeaveCriticalSection(&impl_from_IBaseFilter(This->pin.pinInfo.pFilter)->filter.csFilter); return hr; }
/** * Cycle through available formats using the specified pin, * try to set parameters specified through AVOptions and if successful * return 1 in *pformat_set. * If pformat_set is NULL, list all pin capabilities. */ static void dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, IPin *pin, int *pformat_set) { struct dshow_ctx *ctx = avctx->priv_data; IAMStreamConfig *config = NULL; AM_MEDIA_TYPE *type = NULL; int format_set = 0; void *caps = NULL; int i, n, size; if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (void **) &config) != S_OK) return; if (IAMStreamConfig_GetNumberOfCapabilities(config, &n, &size) != S_OK) goto end; caps = av_malloc(size); if (!caps) goto end; for (i = 0; i < n && !format_set; i++) { IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps); #if DSHOWDEBUG ff_print_AM_MEDIA_TYPE(type); #endif if (devtype == VideoDevice) { VIDEO_STREAM_CONFIG_CAPS *vcaps = caps; BITMAPINFOHEADER *bih; int64_t *fr; #if DSHOWDEBUG ff_print_VIDEO_STREAM_CONFIG_CAPS(vcaps); #endif if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) { VIDEOINFOHEADER *v = (void *) type->pbFormat; fr = &v->AvgTimePerFrame; bih = &v->bmiHeader; } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) { VIDEOINFOHEADER2 *v = (void *) type->pbFormat; fr = &v->AvgTimePerFrame; bih = &v->bmiHeader; } else { goto next; } if (!pformat_set) { av_log(avctx, AV_LOG_INFO, " min s=%ldx%ld fps=%g max s=%ldx%ld fps=%g\n", vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy, 1e7 / vcaps->MaxFrameInterval, vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy, 1e7 / vcaps->MinFrameInterval); continue; } if (ctx->framerate) { int64_t framerate = ((int64_t) ctx->requested_framerate.den*10000000) / ctx->requested_framerate.num; if (framerate > vcaps->MaxFrameInterval || framerate < vcaps->MinFrameInterval) goto next; *fr = framerate; } if (ctx->video_size) { if (ctx->requested_width > vcaps->MaxOutputSize.cx || ctx->requested_width < vcaps->MinOutputSize.cx || ctx->requested_height > vcaps->MaxOutputSize.cy || ctx->requested_height < vcaps->MinOutputSize.cy) goto next; bih->biWidth = ctx->requested_width; bih->biHeight = ctx->requested_height; } } else { AUDIO_STREAM_CONFIG_CAPS *acaps = caps; WAVEFORMATEX *fx; #if DSHOWDEBUG ff_print_AUDIO_STREAM_CONFIG_CAPS(acaps); #endif if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) { fx = (void *) type->pbFormat; } else { goto next; } if (!pformat_set) { av_log(avctx, AV_LOG_INFO, " min ch=%lu bits=%lu rate=%6lu max ch=%lu bits=%lu rate=%6lu\n", acaps->MinimumChannels, acaps->MinimumBitsPerSample, acaps->MinimumSampleFrequency, acaps->MaximumChannels, acaps->MaximumBitsPerSample, acaps->MaximumSampleFrequency); continue; } if (ctx->sample_rate) { if (ctx->sample_rate > acaps->MaximumSampleFrequency || ctx->sample_rate < acaps->MinimumSampleFrequency) goto next; fx->nSamplesPerSec = ctx->sample_rate; } if (ctx->sample_size) { if (ctx->sample_size > acaps->MaximumBitsPerSample || ctx->sample_size < acaps->MinimumBitsPerSample) goto next; fx->wBitsPerSample = ctx->sample_size; } if (ctx->channels) { if (ctx->channels > acaps->MaximumChannels || ctx->channels < acaps->MinimumChannels) goto next; fx->nChannels = ctx->channels; } } if (IAMStreamConfig_SetFormat(config, type) != S_OK) goto next; format_set = 1; next: if (type->pbFormat) CoTaskMemFree(type->pbFormat); CoTaskMemFree(type); } end: IAMStreamConfig_Release(config); if (caps) av_free(caps); if (pformat_set) *pformat_set = format_set; }
static HRESULT WINAPI KSP_QueryInterface(IKsPropertySet * iface, REFIID riid, void **ret_iface) { VfwPinImpl *This = impl_from_IKsPropertySet(iface); return IPin_QueryInterface(&This->pin.pin.IPin_iface, riid, ret_iface); }