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;
358 if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) {
359 VIDEOINFOHEADER *
v = (
void *) type->pbFormat;
360 fr = &v->AvgTimePerFrame;
362 }
else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) {
363 VIDEOINFOHEADER2 *
v = (
void *) type->pbFormat;
364 fr = &v->AvgTimePerFrame;
375 av_log(avctx,
AV_LOG_INFO,
" unknown compression type 0x%X", (
int) bih->biCompression);
383 vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy,
384 1e7 / vcaps->MaxFrameInterval,
385 vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy,
386 1e7 / vcaps->MinFrameInterval);
400 if (framerate > vcaps->MaxFrameInterval ||
401 framerate < vcaps->MinFrameInterval)
415 AUDIO_STREAM_CONFIG_CAPS *acaps = caps;
420 if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) {
421 fx = (
void *) type->pbFormat;
426 av_log(avctx,
AV_LOG_INFO,
" min ch=%lu bits=%lu rate=%6lu max ch=%lu bits=%lu rate=%6lu\n",
427 acaps->MinimumChannels, acaps->MinimumBitsPerSample, acaps->MinimumSampleFrequency,
428 acaps->MaximumChannels, acaps->MaximumBitsPerSample, acaps->MaximumSampleFrequency);
432 if (ctx->
sample_rate > acaps->MaximumSampleFrequency ||
438 if (ctx->
sample_size > acaps->MaximumBitsPerSample ||
444 if (ctx->
channels > acaps->MaximumChannels ||
445 ctx->
channels < acaps->MinimumChannels)
450 if (IAMStreamConfig_SetFormat(config, type) !=
S_OK)
455 CoTaskMemFree(type->pbFormat);
459 IAMStreamConfig_Release(config);
463 *pformat_set = format_set;
474 IAMBufferNegotiation *buffer_negotiation = NULL;
475 ALLOCATOR_PROPERTIES props = { -1, -1, -1, -1 };
476 IAMStreamConfig *
config = NULL;
477 AM_MEDIA_TYPE *
type = NULL;
480 if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (
void **) &config) !=
S_OK)
482 if (IAMStreamConfig_GetFormat(config, &type) !=
S_OK)
484 if (!IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx))
487 props.cbBuffer = (((WAVEFORMATEX *) type->pbFormat)->nAvgBytesPerSec)
490 if (IPin_QueryInterface(pin, &IID_IAMBufferNegotiation, (
void **) &buffer_negotiation) !=
S_OK)
492 if (IAMBufferNegotiation_SuggestAllocatorProperties(buffer_negotiation, &props) !=
S_OK)
498 if (buffer_negotiation)
499 IAMBufferNegotiation_Release(buffer_negotiation);
502 CoTaskMemFree(type->pbFormat);
506 IAMStreamConfig_Release(config);
527 const GUID *mediatype[2] = { &MEDIATYPE_Video, &MEDIATYPE_Audio };
528 const char *devtypename = (devtype ==
VideoDevice) ?
"video" :
"audio";
537 r = IBaseFilter_EnumPins(device_filter, &pins);
547 while (!device_pin && IEnumPins_Next(pins, 1, &pin, NULL) ==
S_OK) {
548 IKsPropertySet *p = NULL;
549 IEnumMediaTypes *types = NULL;
555 IPin_QueryPinInfo(pin, &info);
556 IBaseFilter_Release(info.pFilter);
558 if (info.dir != PINDIR_OUTPUT)
560 if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (
void **) &p) !=
S_OK)
562 if (IKsPropertySet_Get(p, &ROPSETID_Pin, AMPROPERTY_PIN_CATEGORY,
563 NULL, 0, &category,
sizeof(
GUID), &r2) !=
S_OK)
565 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;
778 if (bih->biCompression ==
MKTAG(
'H',
'D',
'Y',
'C')) {
786 "Please report type 0x%X.\n", (
int) bih->biCompression);
792 if (bih->biCompression == BI_RGB || bih->biCompression == BI_BITFIELDS) {
802 WAVEFORMATEX *fx = NULL;
804 if (IsEqualGUID(&type.formattype, &FORMAT_WaveFormatEx)) {
805 fx = (
void *) type.pbFormat;
836 while ((type = strtok(tmp,
"="))) {
837 char *token = strtok(NULL,
":");
840 if (!strcmp(type,
"video")) {
841 device_name[0] = token;
842 }
else if (!strcmp(type,
"audio")) {
843 device_name[1] = token;
845 device_name[0] = NULL;
846 device_name[1] = NULL;
851 if (!device_name[0] && !device_name[1]) {
855 device_name[0] =
av_strdup(device_name[0]);
857 device_name[1] =
av_strdup(device_name[1]);
867 IGraphBuilder *
graph = NULL;
868 ICreateDevEnum *devenum = NULL;
871 HANDLE media_event_handle;
888 "video codec is not set or set to rawvideo\n");
901 r = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
902 &IID_IGraphBuilder, (
void **) &graph);
909 r = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
910 &IID_ICreateDevEnum, (
void **) &devenum);
949 ctx->
mutex = CreateMutex(NULL, 0, NULL);
954 ctx->
event[1] = CreateEvent(NULL, 1, 0, NULL);
955 if (!ctx->
event[1]) {
960 r = IGraphBuilder_QueryInterface(graph, &IID_IMediaControl, (
void **) &control);
967 r = IGraphBuilder_QueryInterface(graph, &IID_IMediaEvent, (
void **) &media_event);
974 r = IMediaEvent_GetEventHandle(media_event, (
void *) &media_event_handle);
979 proc = GetCurrentProcess();
980 r = DuplicateHandle(proc, media_event_handle, proc, &ctx->
event[0],
981 0, 0, DUPLICATE_SAME_ACCESS);
987 r = IMediaControl_Run(control);
990 r = IMediaControl_GetState(control, 0, &pfs);
1002 ICreateDevEnum_Release(devenum);
1021 while (IMediaEvent_GetEvent(media_event, &code, &p1, &p2, 0) != E_ABORT) {
1022 if (code == EC_COMPLETE || code ==
EC_DEVICE_LOST || code == EC_ERRORABORT)
1024 IMediaEvent_FreeEventParams(media_event, code, p1, p2);
1035 while (!ctx->
eof && !pktl) {
1036 WaitForSingleObject(ctx->
mutex, INFINITE);
1044 ResetEvent(ctx->
event[1]);
1045 ReleaseMutex(ctx->
mutex);
1052 WaitForMultipleObjects(2, ctx->
event, 0, INFINITE);
1060 #define OFFSET(x) offsetof(struct dshow_ctx, x)
1061 #define DEC AV_OPT_FLAG_DECODING_PARAM
1092 .priv_data_size =
sizeof(
struct dshow_ctx),