75 switch(biCompression) {
76 case MKTAG(
'U',
'Y',
'V',
'Y'):
78 case MKTAG(
'Y',
'U',
'Y',
'2'):
80 case MKTAG(
'I',
'4',
'2',
'0'):
104 switch(biCompression) {
105 case MKTAG(
'd',
'v',
's',
'd'):
107 case MKTAG(
'M',
'J',
'P',
'G'):
108 case MKTAG(
'm',
'j',
'p',
'g'):
121 IMediaControl_Stop(ctx->
control);
122 IMediaControl_Release(ctx->
control);
131 r = IGraphBuilder_EnumFilters(ctx->
graph, &fenum);
134 IEnumFilters_Reset(fenum);
135 while (IEnumFilters_Next(fenum, 1, &f,
NULL) == S_OK) {
136 if (IGraphBuilder_RemoveFilter(ctx->
graph, f) == S_OK)
137 IEnumFilters_Reset(fenum);
139 IBaseFilter_Release(f);
141 IEnumFilters_Release(fenum);
143 IGraphBuilder_Release(ctx->
graph);
170 CloseHandle(ctx->
mutex);
172 CloseHandle(ctx->
event[0]);
174 CloseHandle(ctx->
event[1]);
192 int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
195 WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
202 const uint8_t dropscore[] = {62, 75, 87, 100};
208 "real-time buffer %d%% full! frame dropped!\n", buffer_fullness);
224 WaitForSingleObject(ctx->
mutex, INFINITE);
239 pktl_next->
pkt.
pts = time;
240 memcpy(pktl_next->
pkt.
data, buf, buf_size);
242 for(ppktl = &ctx->
pktl ; *ppktl ; ppktl = &(*ppktl)->
next);
247 SetEvent(ctx->
event[1]);
248 ReleaseMutex(ctx->
mutex);
252 ReleaseMutex(ctx->
mutex);
268 IEnumMoniker *classenum =
NULL;
275 const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory,
276 &CLSID_AudioInputDeviceCategory };
277 const char *devtypename = (devtype ==
VideoDevice) ?
"video" :
"audio";
279 r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[devtype],
280 (IEnumMoniker **) &classenum, 0);
288 IPropertyBag *bag =
NULL;
292 r = IMoniker_BindToStorage(
m, 0, 0, &IID_IPropertyBag, (
void *) &bag);
297 r = IPropertyBag_Read(bag,
L"FriendlyName", &var,
NULL);
308 IMoniker_BindToObject(
m, 0, 0, &IID_IBaseFilter, (
void *) &
device_filter);
317 IPropertyBag_Release(bag);
321 IEnumMoniker_Release(classenum);
343 IPin *pin,
int *pformat_set)
347 AM_MEDIA_TYPE *type =
NULL;
352 if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (
void **) &config) != S_OK)
354 if (IAMStreamConfig_GetNumberOfCapabilities(config, &n, &size) != S_OK)
361 for (i = 0; i < n && !format_set; i++) {
362 IAMStreamConfig_GetStreamCaps(config, i, &type, (
void *) caps);
369 VIDEO_STREAM_CONFIG_CAPS *vcaps = caps;
370 BITMAPINFOHEADER *bih;
375 if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) {
376 VIDEOINFOHEADER *v = (
void *) type->pbFormat;
377 fr = &v->AvgTimePerFrame;
379 }
else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) {
380 VIDEOINFOHEADER2 *v = (
void *) type->pbFormat;
381 fr = &v->AvgTimePerFrame;
392 av_log(avctx,
AV_LOG_INFO,
" unknown compression type 0x%X", (
int) bih->biCompression);
400 vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy,
401 1e7 / vcaps->MaxFrameInterval,
402 vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy,
403 1e7 / vcaps->MinFrameInterval);
417 if (framerate > vcaps->MaxFrameInterval ||
418 framerate < vcaps->MinFrameInterval)
432 AUDIO_STREAM_CONFIG_CAPS *acaps = caps;
437 if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) {
438 fx = (
void *) type->pbFormat;
443 av_log(avctx,
AV_LOG_INFO,
" min ch=%lu bits=%lu rate=%6lu max ch=%lu bits=%lu rate=%6lu\n",
444 acaps->MinimumChannels, acaps->MinimumBitsPerSample, acaps->MinimumSampleFrequency,
445 acaps->MaximumChannels, acaps->MaximumBitsPerSample, acaps->MaximumSampleFrequency);
449 if (ctx->
sample_rate > acaps->MaximumSampleFrequency ||
455 if (ctx->
sample_size > acaps->MaximumBitsPerSample ||
461 if (ctx->
channels > acaps->MaximumChannels ||
462 ctx->
channels < acaps->MinimumChannels)
467 if (IAMStreamConfig_SetFormat(config, type) != S_OK)
472 CoTaskMemFree(type->pbFormat);
476 IAMStreamConfig_Release(config);
480 *pformat_set = format_set;
491 IAMBufferNegotiation *buffer_negotiation =
NULL;
492 ALLOCATOR_PROPERTIES props = { -1, -1, -1, -1 };
494 AM_MEDIA_TYPE *type =
NULL;
497 if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (
void **) &config) != S_OK)
499 if (IAMStreamConfig_GetFormat(config, &type) != S_OK)
501 if (!IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx))
504 props.cbBuffer = (((WAVEFORMATEX *) type->pbFormat)->nAvgBytesPerSec)
507 if (IPin_QueryInterface(pin, &IID_IAMBufferNegotiation, (
void **) &buffer_negotiation) != S_OK)
509 if (IAMBufferNegotiation_SuggestAllocatorProperties(buffer_negotiation, &props) != S_OK)
515 if (buffer_negotiation)
516 IAMBufferNegotiation_Release(buffer_negotiation);
519 CoTaskMemFree(type->pbFormat);
523 IAMStreamConfig_Release(config);
544 const GUID *mediatype[2] = { &MEDIATYPE_Video, &MEDIATYPE_Audio };
545 const char *devtypename = (devtype ==
VideoDevice) ?
"video" :
"audio";
554 r = IBaseFilter_EnumPins(device_filter, &pins);
564 while (!device_pin && IEnumPins_Next(pins, 1, &pin,
NULL) == S_OK) {
565 IKsPropertySet *p =
NULL;
566 IEnumMediaTypes *types =
NULL;
572 IPin_QueryPinInfo(pin, &info);
573 IBaseFilter_Release(info.pFilter);
575 if (info.dir != PINDIR_OUTPUT)
577 if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (
void **) &p) != S_OK)
579 if (IKsPropertySet_Get(p, &ROPSETID_Pin, AMPROPERTY_PIN_CATEGORY,
580 NULL, 0, &category,
sizeof(GUID), &r2) != S_OK)
582 if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE))
603 if (IPin_EnumMediaTypes(pin, &types) != S_OK)
606 IEnumMediaTypes_Reset(types);
607 while (!device_pin && IEnumMediaTypes_Next(types, 1, &type,
NULL) == S_OK) {
608 if (IsEqualGUID(&type->majortype, mediatype[devtype])) {
617 IEnumMediaTypes_Release(types);
619 IKsPropertySet_Release(p);
620 if (device_pin != pin)
624 IEnumPins_Release(pins);
627 if (set_format && !format_set) {
633 "Could not find output pin from %s capture device.\n", devtypename);
677 const wchar_t *filter_name[2] = {
L"Audio capture filter",
L"Video capture filter" };
686 r = IGraphBuilder_AddFilter(graph, device_filter,
NULL);
692 if ((r =
dshow_cycle_pins(avctx, devtype, device_filter, &device_pin)) < 0) {
699 if (!capture_filter) {
705 r = IGraphBuilder_AddFilter(graph, (IBaseFilter *) capture_filter,
706 filter_name[devtype]);
713 capture_pin = capture_filter->
pin;
716 r = IGraphBuilder_ConnectDirect(graph, device_pin, (IPin *) capture_pin,
NULL);
730 switch (sample_fmt) {
771 BITMAPINFOHEADER *bih =
NULL;
774 if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo)) {
775 VIDEOINFOHEADER *v = (
void *) type.pbFormat;
776 time_base = (
AVRational) { v->AvgTimePerFrame, 10000000 };
778 }
else if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo2)) {
779 VIDEOINFOHEADER2 *v = (
void *) type.pbFormat;
780 time_base = (
AVRational) { v->AvgTimePerFrame, 10000000 };
790 codec->
width = bih->biWidth;
791 codec->
height = bih->biHeight;
797 "Please report verbose (-v 9) debug information.\n");
803 if (bih->biCompression == BI_RGB || bih->biCompression == BI_BITFIELDS) {
813 WAVEFORMATEX *fx =
NULL;
815 if (IsEqualGUID(&type.formattype, &FORMAT_WaveFormatEx)) {
816 fx = (
void *) type.pbFormat;
847 while ((type = strtok(tmp,
"="))) {
848 char *token = strtok(
NULL,
":");
851 if (!strcmp(type,
"video")) {
852 device_name[0] = token;
853 }
else if (!strcmp(type,
"audio")) {
854 device_name[1] = token;
856 device_name[0] =
NULL;
857 device_name[1] =
NULL;
862 if (!device_name[0] && !device_name[1]) {
866 device_name[0] =
av_strdup(device_name[0]);
868 device_name[1] =
av_strdup(device_name[1]);
879 ICreateDevEnum *devenum =
NULL;
882 HANDLE media_event_handle;
899 "video codec is not set or set to rawvideo\n");
912 r = CoCreateInstance(&CLSID_FilterGraph,
NULL, CLSCTX_INPROC_SERVER,
913 &IID_IGraphBuilder, (
void **) &graph);
920 r = CoCreateInstance(&CLSID_SystemDeviceEnum,
NULL, CLSCTX_INPROC_SERVER,
921 &IID_ICreateDevEnum, (
void **) &devenum);
965 if (!ctx->
event[1]) {
970 r = IGraphBuilder_QueryInterface(graph, &IID_IMediaControl, (
void **) &control);
977 r = IGraphBuilder_QueryInterface(graph, &IID_IMediaEvent, (
void **) &media_event);
984 r = IMediaEvent_GetEventHandle(media_event, (
void *) &media_event_handle);
989 proc = GetCurrentProcess();
990 r = DuplicateHandle(proc, media_event_handle, proc, &ctx->
event[0],
991 0, 0, DUPLICATE_SAME_ACCESS);
997 r = IMediaControl_Run(control);
1000 r = IMediaControl_GetState(control, 0, &pfs);
1012 ICreateDevEnum_Release(devenum);
1031 while (IMediaEvent_GetEvent(media_event, &code, &p1, &p2, 0) != E_ABORT) {
1032 if (code == EC_COMPLETE || code ==
EC_DEVICE_LOST || code == EC_ERRORABORT)
1034 IMediaEvent_FreeEventParams(media_event, code, p1, p2);
1045 while (!ctx->
eof && !pktl) {
1046 WaitForSingleObject(ctx->
mutex, INFINITE);
1054 ResetEvent(ctx->
event[1]);
1055 ReleaseMutex(ctx->
mutex);
1062 WaitForMultipleObjects(2, ctx->
event, 0, INFINITE);
1070 #define OFFSET(x) offsetof(struct dshow_ctx, x)
1071 #define DEC AV_OPT_FLAG_DECODING_PARAM
1101 .priv_data_size =
sizeof(
struct dshow_ctx),