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};
192 "real-time buffer %d%% full! frame dropped!\n", buffer_fullness);
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);
231 SetEvent(ctx->
event[1]);
232 ReleaseMutex(ctx->
mutex);
236 ReleaseMutex(ctx->
mutex);
252 IEnumMoniker *classenum = NULL;
259 const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory,
260 &CLSID_AudioInputDeviceCategory };
261 const char *devtypename = (devtype ==
VideoDevice) ?
"video" :
"audio";
263 r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[devtype],
264 (IEnumMoniker **) &classenum, 0);
272 IPropertyBag *bag = NULL;
276 r = IMoniker_BindToStorage(
m, 0, 0, &IID_IPropertyBag, (
void *) &bag);
281 r = IPropertyBag_Read(bag,
L"FriendlyName", &var, NULL);
292 IMoniker_BindToObject(
m, 0, 0, &IID_IBaseFilter, (
void *) &
device_filter);
301 IPropertyBag_Release(bag);
305 IEnumMoniker_Release(classenum);
327 IPin *pin,
int *pformat_set)
330 IAMStreamConfig *
config = NULL;
331 AM_MEDIA_TYPE *
type = NULL;
336 if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (
void **) &config) !=
S_OK)
338 if (IAMStreamConfig_GetNumberOfCapabilities(config, &n, &size) !=
S_OK)
345 for (i = 0; i < n && !format_set; i++) {
346 IAMStreamConfig_GetStreamCaps(config, i, &type, (
void *) caps);
353 VIDEO_STREAM_CONFIG_CAPS *vcaps = caps;
354 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))
587 if (IPin_EnumMediaTypes(pin, &types) !=
S_OK)
590 IEnumMediaTypes_Reset(types);
591 while (!device_pin && IEnumMediaTypes_Next(types, 1, &type, NULL) ==
S_OK) {
592 if (IsEqualGUID(&type->majortype, mediatype[devtype])) {
601 IEnumMediaTypes_Release(types);
603 IKsPropertySet_Release(p);
604 if (device_pin != pin)
608 IEnumPins_Release(pins);
611 if (set_format && !format_set) {
617 "Could not find output pin from %s capture device.\n", devtypename);
661 const wchar_t *filter_name[2] = {
L"Audio capture filter",
L"Video capture filter" };
670 r = IGraphBuilder_AddFilter(graph, device_filter, NULL);
676 if ((r =
dshow_cycle_pins(avctx, devtype, device_filter, &device_pin)) < 0) {
683 if (!capture_filter) {
689 r = IGraphBuilder_AddFilter(graph, (IBaseFilter *) capture_filter,
690 filter_name[devtype]);
697 capture_pin = capture_filter->
pin;
700 r = IGraphBuilder_ConnectDirect(graph, device_pin, (IPin *) capture_pin, NULL);
714 switch (sample_fmt) {
755 BITMAPINFOHEADER *bih = NULL;
758 if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo)) {
759 VIDEOINFOHEADER *
v = (
void *) type.pbFormat;
760 time_base = (
AVRational) { v->AvgTimePerFrame, 10000000 };
762 }
else if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo2)) {
763 VIDEOINFOHEADER2 *
v = (
void *) type.pbFormat;
764 time_base = (
AVRational) { v->AvgTimePerFrame, 10000000 };
774 codec->
width = bih->biWidth;
775 codec->
height = bih->biHeight;
777 if (bih->biCompression ==
MKTAG(
'H',
'D',
'Y',
'C')) {
785 "Please report type 0x%X.\n", (
int) bih->biCompression);
791 if (bih->biCompression == BI_RGB || bih->biCompression == BI_BITFIELDS) {
801 WAVEFORMATEX *fx = NULL;
803 if (IsEqualGUID(&type.formattype, &FORMAT_WaveFormatEx)) {
804 fx = (
void *) type.pbFormat;
835 while ((type = strtok(tmp,
"="))) {
836 char *token = strtok(NULL,
":");
839 if (!strcmp(type,
"video")) {
840 device_name[0] = token;
841 }
else if (!strcmp(type,
"audio")) {
842 device_name[1] = token;
844 device_name[0] = NULL;
845 device_name[1] = NULL;
850 if (!device_name[0] && !device_name[1]) {
854 device_name[0] =
av_strdup(device_name[0]);
856 device_name[1] =
av_strdup(device_name[1]);
866 IGraphBuilder *
graph = NULL;
867 ICreateDevEnum *devenum = NULL;
870 HANDLE media_event_handle;
887 "video codec is not set or set to rawvideo\n");
900 r = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
901 &IID_IGraphBuilder, (
void **) &graph);
908 r = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
909 &IID_ICreateDevEnum, (
void **) &devenum);
947 ctx->
mutex = CreateMutex(NULL, 0, NULL);
952 ctx->
event[1] = CreateEvent(NULL, 1, 0, NULL);
953 if (!ctx->
event[1]) {
958 r = IGraphBuilder_QueryInterface(graph, &IID_IMediaControl, (
void **) &control);
965 r = IGraphBuilder_QueryInterface(graph, &IID_IMediaEvent, (
void **) &media_event);
972 r = IMediaEvent_GetEventHandle(media_event, (
void *) &media_event_handle);
977 proc = GetCurrentProcess();
978 r = DuplicateHandle(proc, media_event_handle, proc, &ctx->
event[0],
979 0, 0, DUPLICATE_SAME_ACCESS);
985 r = IMediaControl_Run(control);
988 r = IMediaControl_GetState(control, 0, &pfs);
1000 ICreateDevEnum_Release(devenum);
1019 while (IMediaEvent_GetEvent(media_event, &code, &p1, &p2, 0) != E_ABORT) {
1020 if (code == EC_COMPLETE || code ==
EC_DEVICE_LOST || code == EC_ERRORABORT)
1022 IMediaEvent_FreeEventParams(media_event, code, p1, p2);
1033 while (!ctx->
eof && !pktl) {
1034 WaitForSingleObject(ctx->
mutex, INFINITE);
1042 ResetEvent(ctx->
event[1]);
1043 ReleaseMutex(ctx->
mutex);
1050 WaitForMultipleObjects(2, ctx->
event, 0, INFINITE);
1058 #define OFFSET(x) offsetof(struct dshow_ctx, x)
1059 #define DEC AV_OPT_FLAG_DECODING_PARAM
1089 .priv_data_size =
sizeof(
struct dshow_ctx),