77 switch(biCompression) {
105 IMediaControl_Stop(ctx->
control);
106 IMediaControl_Release(ctx->
control);
115 r = IGraphBuilder_EnumFilters(ctx->
graph, &fenum);
118 IEnumFilters_Reset(fenum);
119 while (IEnumFilters_Next(fenum, 1, &f, NULL) ==
S_OK) {
120 if (IGraphBuilder_RemoveFilter(ctx->
graph, f) ==
S_OK)
121 IEnumFilters_Reset(fenum);
123 IBaseFilter_Release(f);
125 IEnumFilters_Release(fenum);
127 IGraphBuilder_Release(ctx->
graph);
154 CloseHandle(ctx->
mutex);
156 CloseHandle(ctx->
event[0]);
158 CloseHandle(ctx->
event[1]);
176 int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
179 WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
186 static const uint8_t dropscore[] = {62, 75, 87, 100};
208 WaitForSingleObject(ctx->
mutex, INFINITE);
223 pktl_next->
pkt.
pts = time;
224 memcpy(pktl_next->
pkt.
data, buf, buf_size);
226 for(ppktl = &ctx->
pktl ; *ppktl ; ppktl = &(*ppktl)->
next);
230 SetEvent(ctx->
event[1]);
231 ReleaseMutex(ctx->
mutex);
235 ReleaseMutex(ctx->
mutex);
251 IEnumMoniker *classenum = NULL;
258 const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory,
259 &CLSID_AudioInputDeviceCategory };
260 const char *devtypename = (devtype ==
VideoDevice) ?
"video" :
"audio";
262 r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[devtype],
263 (IEnumMoniker **) &classenum, 0);
271 IPropertyBag *bag = NULL;
275 r = IMoniker_BindToStorage(
m, 0, 0, &IID_IPropertyBag, (
void *) &bag);
280 r = IPropertyBag_Read(bag,
L"FriendlyName", &var, NULL);
291 IMoniker_BindToObject(
m, 0, 0, &IID_IBaseFilter, (
void *) &
device_filter);
300 IPropertyBag_Release(bag);
304 IEnumMoniker_Release(classenum);
326 IPin *pin,
int *pformat_set)
329 IAMStreamConfig *
config = NULL;
330 AM_MEDIA_TYPE *
type = NULL;
335 if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (
void **) &config) !=
S_OK)
337 if (IAMStreamConfig_GetNumberOfCapabilities(config, &n, &size) !=
S_OK)
344 for (i = 0; i < n && !format_set; i++) {
345 IAMStreamConfig_GetStreamCaps(config, i, &type, (
void *) caps);
352 VIDEO_STREAM_CONFIG_CAPS *vcaps = caps;
353 BITMAPINFOHEADER *bih;
359 if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) {
360 VIDEOINFOHEADER *
v = (
void *) type->pbFormat;
361 fr = &v->AvgTimePerFrame;
363 }
else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) {
364 VIDEOINFOHEADER2 *
v = (
void *) type->pbFormat;
365 fr = &v->AvgTimePerFrame;
376 av_log(avctx,
AV_LOG_INFO,
" unknown compression type 0x%X", (
int) bih->biCompression);
384 vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy,
385 1e7 / vcaps->MaxFrameInterval,
386 vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy,
387 1e7 / vcaps->MinFrameInterval);
401 if (framerate > vcaps->MaxFrameInterval ||
402 framerate < vcaps->MinFrameInterval)
416 AUDIO_STREAM_CONFIG_CAPS *acaps = caps;
421 if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) {
422 fx = (
void *) type->pbFormat;
427 av_log(avctx,
AV_LOG_INFO,
" min ch=%lu bits=%lu rate=%6lu max ch=%lu bits=%lu rate=%6lu\n",
428 acaps->MinimumChannels, acaps->MinimumBitsPerSample, acaps->MinimumSampleFrequency,
429 acaps->MaximumChannels, acaps->MaximumBitsPerSample, acaps->MaximumSampleFrequency);
433 if (ctx->
sample_rate > acaps->MaximumSampleFrequency ||
439 if (ctx->
sample_size > acaps->MaximumBitsPerSample ||
445 if (ctx->
channels > acaps->MaximumChannels ||
446 ctx->
channels < acaps->MinimumChannels)
451 if (IAMStreamConfig_SetFormat(config, type) !=
S_OK)
456 CoTaskMemFree(type->pbFormat);
460 IAMStreamConfig_Release(config);
464 *pformat_set = format_set;
475 IAMBufferNegotiation *buffer_negotiation = NULL;
476 ALLOCATOR_PROPERTIES props = { -1, -1, -1, -1 };
477 IAMStreamConfig *
config = NULL;
478 AM_MEDIA_TYPE *
type = NULL;
481 if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (
void **) &config) !=
S_OK)
483 if (IAMStreamConfig_GetFormat(config, &type) !=
S_OK)
485 if (!IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx))
488 props.cbBuffer = (((WAVEFORMATEX *) type->pbFormat)->nAvgBytesPerSec)
491 if (IPin_QueryInterface(pin, &IID_IAMBufferNegotiation, (
void **) &buffer_negotiation) !=
S_OK)
493 if (IAMBufferNegotiation_SuggestAllocatorProperties(buffer_negotiation, &props) !=
S_OK)
499 if (buffer_negotiation)
500 IAMBufferNegotiation_Release(buffer_negotiation);
503 CoTaskMemFree(type->pbFormat);
507 IAMStreamConfig_Release(config);
528 const GUID *mediatype[2] = { &MEDIATYPE_Video, &MEDIATYPE_Audio };
529 const char *devtypename = (devtype ==
VideoDevice) ?
"video" :
"audio";
538 r = IBaseFilter_EnumPins(device_filter, &pins);
548 while (!device_pin && IEnumPins_Next(pins, 1, &pin, NULL) ==
S_OK) {
549 IKsPropertySet *p = NULL;
550 IEnumMediaTypes *types = NULL;
556 IPin_QueryPinInfo(pin, &info);
557 IBaseFilter_Release(info.pFilter);
559 if (info.dir != PINDIR_OUTPUT)
561 if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (
void **) &p) !=
S_OK)
563 if (IKsPropertySet_Get(p, &ROPSETID_Pin, AMPROPERTY_PIN_CATEGORY,
564 NULL, 0, &category,
sizeof(
GUID), &r2) !=
S_OK)
566 if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE))
588 if (IPin_EnumMediaTypes(pin, &types) !=
S_OK)
591 IEnumMediaTypes_Reset(types);
592 while (!device_pin && IEnumMediaTypes_Next(types, 1, &type, NULL) ==
S_OK) {
593 if (IsEqualGUID(&type->majortype, mediatype[devtype])) {
602 IEnumMediaTypes_Release(types);
604 IKsPropertySet_Release(p);
605 if (device_pin != pin)
609 IEnumPins_Release(pins);
612 if (set_format && !format_set) {
618 "Could not find output pin from %s capture device.\n", devtypename);
662 const wchar_t *filter_name[2] = {
L"Audio capture filter",
L"Video capture filter" };
671 r = IGraphBuilder_AddFilter(graph, device_filter, NULL);
677 if ((r =
dshow_cycle_pins(avctx, devtype, device_filter, &device_pin)) < 0) {
684 if (!capture_filter) {
690 r = IGraphBuilder_AddFilter(graph, (IBaseFilter *) capture_filter,
691 filter_name[devtype]);
698 capture_pin = capture_filter->
pin;
701 r = IGraphBuilder_ConnectDirect(graph, device_pin, (IPin *) capture_pin, NULL);
715 switch (sample_fmt) {
756 BITMAPINFOHEADER *bih = NULL;
759 if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo)) {
760 VIDEOINFOHEADER *
v = (
void *) type.pbFormat;
761 time_base = (
AVRational) { v->AvgTimePerFrame, 10000000 };
763 }
else if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo2)) {
764 VIDEOINFOHEADER2 *
v = (
void *) type.pbFormat;
765 time_base = (
AVRational) { v->AvgTimePerFrame, 10000000 };
775 codec->
width = bih->biWidth;
776 codec->
height = bih->biHeight;
779 if (bih->biCompression ==
MKTAG(
'H',
'D',
'Y',
'C')) {
788 "Please report type 0x%X.\n", (
int) bih->biCompression);
794 if (bih->biCompression == BI_RGB || bih->biCompression == BI_BITFIELDS) {
804 WAVEFORMATEX *fx = NULL;
806 if (IsEqualGUID(&type.formattype, &FORMAT_WaveFormatEx)) {
807 fx = (
void *) type.pbFormat;
838 while ((type = strtok(tmp,
"="))) {
839 char *token = strtok(NULL,
":");
842 if (!strcmp(type,
"video")) {
843 device_name[0] = token;
844 }
else if (!strcmp(type,
"audio")) {
845 device_name[1] = token;
847 device_name[0] = NULL;
848 device_name[1] = NULL;
853 if (!device_name[0] && !device_name[1]) {
857 device_name[0] =
av_strdup(device_name[0]);
859 device_name[1] =
av_strdup(device_name[1]);
869 IGraphBuilder *
graph = NULL;
870 ICreateDevEnum *devenum = NULL;
873 HANDLE media_event_handle;
890 "video codec is not set or set to rawvideo\n");
903 r = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
904 &IID_IGraphBuilder, (
void **) &graph);
911 r = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
912 &IID_ICreateDevEnum, (
void **) &devenum);
951 ctx->
mutex = CreateMutex(NULL, 0, NULL);
956 ctx->
event[1] = CreateEvent(NULL, 1, 0, NULL);
957 if (!ctx->
event[1]) {
962 r = IGraphBuilder_QueryInterface(graph, &IID_IMediaControl, (
void **) &control);
969 r = IGraphBuilder_QueryInterface(graph, &IID_IMediaEvent, (
void **) &media_event);
976 r = IMediaEvent_GetEventHandle(media_event, (
void *) &media_event_handle);
981 proc = GetCurrentProcess();
982 r = DuplicateHandle(proc, media_event_handle, proc, &ctx->
event[0],
983 0, 0, DUPLICATE_SAME_ACCESS);
989 r = IMediaControl_Run(control);
992 r = IMediaControl_GetState(control, 0, &pfs);
1004 ICreateDevEnum_Release(devenum);
1023 while (IMediaEvent_GetEvent(media_event, &code, &p1, &p2, 0) != E_ABORT) {
1024 if (code == EC_COMPLETE || code ==
EC_DEVICE_LOST || code == EC_ERRORABORT)
1026 IMediaEvent_FreeEventParams(media_event, code, p1, p2);
1037 while (!ctx->
eof && !pktl) {
1038 WaitForSingleObject(ctx->
mutex, INFINITE);
1046 ResetEvent(ctx->
event[1]);
1047 ReleaseMutex(ctx->
mutex);
1054 WaitForMultipleObjects(2, ctx->
event, 0, INFINITE);
1062 #define OFFSET(x) offsetof(struct dshow_ctx, x)
1063 #define DEC AV_OPT_FLAG_DECODING_PARAM
1094 .priv_data_size =
sizeof(
struct dshow_ctx),