54#ifndef AMCONTROL_COLORINFO_PRESENT
56# define AMCONTROL_COLORINFO_PRESENT 0x00000080
62 switch(biCompression) {
85 switch (fmt_info->NominalRange)
87 case DXVA2_NominalRange_Unknown:
89 case DXVA2_NominalRange_Normal:
91 case DXVA2_NominalRange_Wide:
93 case DXVA2_NominalRange_48_208:
109 switch (fmt_info->VideoTransferMatrix)
111 case DXVA2_VideoTransferMatrix_BT709:
113 case DXVA2_VideoTransferMatrix_BT601:
115 case DXVA2_VideoTransferMatrix_SMPTE240M:
121 if (fmt_info->VideoTransferFunction == 12)
133 switch (fmt_info->VideoPrimaries)
135 case DXVA2_VideoPrimaries_Unknown:
137 case DXVA2_VideoPrimaries_reserved:
139 case DXVA2_VideoPrimaries_BT709:
141 case DXVA2_VideoPrimaries_BT470_2_SysM:
143 case DXVA2_VideoPrimaries_BT470_2_SysBG:
144 case DXVA2_VideoPrimaries_EBU3213:
146 case DXVA2_VideoPrimaries_SMPTE170M:
147 case DXVA2_VideoPrimaries_SMPTE_C:
149 case DXVA2_VideoPrimaries_SMPTE240M:
170 switch (fmt_info->VideoTransferFunction)
172 case DXVA2_VideoTransFunc_Unknown:
174 case DXVA2_VideoTransFunc_10:
176 case DXVA2_VideoTransFunc_18:
179 case DXVA2_VideoTransFunc_20:
182 case DXVA2_VideoTransFunc_22:
184 case DXVA2_VideoTransFunc_709:
186 case DXVA2_VideoTransFunc_240M:
188 case DXVA2_VideoTransFunc_sRGB:
190 case DXVA2_VideoTransFunc_28:
203 if (fmt_info->VideoTransferMatrix == 5)
225 if (fmt_info->VideoChromaSubsampling == DXVA2_VideoChromaSubsampling_Cosited)
227 else if (fmt_info->VideoChromaSubsampling == DXVA2_VideoChromaSubsampling_MPEG1)
229 else if (fmt_info->VideoChromaSubsampling == DXVA2_VideoChromaSubsampling_MPEG2)
231 else if (fmt_info->VideoChromaSubsampling == DXVA2_VideoChromaSubsampling_DV_PAL)
245 IMediaControl_Stop(
ctx->control);
246 IMediaControl_Release(
ctx->control);
249 if (
ctx->media_event)
250 IMediaEvent_Release(
ctx->media_event);
255 r = IGraphBuilder_EnumFilters(
ctx->graph, &fenum);
258 IEnumFilters_Reset(fenum);
259 while (IEnumFilters_Next(fenum, 1, &
f,
NULL) == S_OK) {
260 if (IGraphBuilder_RemoveFilter(
ctx->graph,
f) == S_OK)
261 IEnumFilters_Reset(fenum);
263 IBaseFilter_Release(
f);
265 IEnumFilters_Release(fenum);
267 IGraphBuilder_Release(
ctx->graph);
294 CloseHandle(
ctx->mutex);
296 CloseHandle(
ctx->event[0]);
298 CloseHandle(
ctx->event[1]);
316 int l = WideCharToMultiByte(CP_UTF8, 0,
w, -1, 0, 0, 0, 0);
319 WideCharToMultiByte(CP_UTF8, 0,
w, -1,
s, l, 0, 0);
326 static const uint8_t dropscore[] = {62, 75, 87, 100};
328 unsigned int buffer_fullness = (
ctx->curbufsize[
index]*100)/
s->max_picture_buffer;
329 const char *devtypename = (devtype ==
VideoDevice) ?
"video" :
"audio";
331 if(dropscore[++
ctx->video_frame_num%ndropscores] <= buffer_fullness) {
333 "real-time buffer [%s] [%s input] too full or near too full (%d%% of size: %d [rtbufsize parameter])! frame dropped!\n",
334 ctx->device_name[devtype], devtypename, buffer_fullness,
s->max_picture_buffer);
365 pktl_next->
pkt.
pts = time;
366 memcpy(pktl_next->
pkt.
data, buf, buf_size);
368 for(ppktl = &
ctx->pktl ; *ppktl ; ppktl = &(*ppktl)->
next);
372 SetEvent(
ctx->event[1]);
373 ReleaseMutex(
ctx->mutex);
377 ReleaseMutex(
ctx->mutex);
384 enum AVMediaType **media_types,
int *nb_media_types)
388 int has_audio = 0, has_video = 0;
393 while (IEnumPins_Next(pins, 1, &pin,
NULL) == S_OK) {
394 IKsPropertySet *p =
NULL;
395 PIN_INFO info = { 0 };
398 IEnumMediaTypes *types =
NULL;
401 if (IPin_QueryPinInfo(pin, &info) != S_OK)
403 IBaseFilter_Release(info.pFilter);
405 if (info.dir != PINDIR_OUTPUT)
407 if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (
void **) &p) != S_OK)
409 if (IKsPropertySet_Get(p, &ROPSETID_Pin, AMPROPERTY_PIN_CATEGORY,
412 if (!IsEqualGUID(&
category, &PIN_CATEGORY_CAPTURE))
415 if (IPin_EnumMediaTypes(pin, &types) != S_OK)
420 IEnumMediaTypes_Reset(types);
421 while (IEnumMediaTypes_Next(types, 1, &
type,
NULL) == S_OK) {
422 if (IsEqualGUID(&
type->majortype, &MEDIATYPE_Video)) {
424 }
else if (IsEqualGUID(&
type->majortype, &MEDIATYPE_Audio)) {
432 IEnumMediaTypes_Release(types);
434 IKsPropertySet_Release(p);
439 IEnumPins_Release(pins);
441 if (has_audio || has_video) {
442 int nb_types = has_audio + has_video;
449 *nb_media_types = nb_types;
470 IEnumMoniker *classenum =
NULL;
474 :
ctx->audio_device_number;
477 const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory,
478 &CLSID_AudioInputDeviceCategory };
479 const char *devtypename = (devtype ==
VideoDevice) ?
"video" :
"audio only";
480 const char *sourcetypename = (sourcetype ==
VideoSourceDevice) ?
"video" :
"audio";
482 r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[sourcetype],
483 (IEnumMoniker **) &classenum, 0);
491 IPropertyBag *bag =
NULL;
493 char *unique_name =
NULL;
495 IBindCtx *bind_ctx =
NULL;
496 LPOLESTR olestr =
NULL;
497 LPMALLOC co_malloc =
NULL;
500 int nb_media_types = 0;
503 r = CoGetMalloc(1, &co_malloc);
506 r = CreateBindCtx(0, &bind_ctx);
510 r = IMoniker_GetDisplayName(m, bind_ctx,
NULL, &olestr);
515 for (
i = 0;
i < strlen(unique_name);
i++) {
516 if (unique_name[
i] ==
':')
517 unique_name[
i] =
'_';
520 r = IMoniker_BindToStorage(m, 0, 0, &IID_IPropertyBag, (
void *) &bag);
525 r = IPropertyBag_Read(bag,
L"FriendlyName", &var,
NULL);
535 r = IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (
void *) &
device_filter);
546 if (IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (
void* ) &
device_filter) == S_OK) {
563 (*device_list)->nb_devices + 1,
564 sizeof(*(*device_list)->devices)) < 0)
574 (*device_list)->devices[(*device_list)->nb_devices] = device;
575 (*device_list)->nb_devices++;
580 if (nb_media_types > 0) {
583 for (
int i = 1;
i < nb_media_types; ++
i) {
604 if (olestr && co_malloc)
605 IMalloc_Free(co_malloc, olestr);
607 IBindCtx_Release(bind_ctx);
611 IPropertyBag_Release(bag);
615 IEnumMoniker_Release(classenum);
619 av_log(avctx,
AV_LOG_ERROR,
"Could not find %s device with name [%s] among source devices of type %s.\n",
631 ICreateDevEnum *devenum =
NULL;
640 r = CoCreateInstance(&CLSID_SystemDeviceEnum,
NULL, CLSCTX_INPROC_SERVER,
641 &IID_ICreateDevEnum, (
void**)&devenum);
648 if (ret < S_OK && ret !=
AVERROR(EIO))
654 ICreateDevEnum_Release(devenum);
666 (
ctx->requested_width &&
ctx->requested_height) ||
696 BITMAPINFOHEADER *bih;
697 DXVA2_ExtendedFormat *extended_format_info =
NULL;
705 if (IsEqualGUID(&
type->formattype, &FORMAT_VideoInfo)) {
706 VIDEOINFOHEADER *v = (
void *)
type->pbFormat;
710 }
else if (IsEqualGUID(&
type->formattype, &FORMAT_VideoInfo2)) {
711 VIDEOINFOHEADER2 *v = (
void *)
type->pbFormat;
716 extended_format_info = (DXVA2_ExtendedFormat *) &v->dwControlFlags;
717 }
else if (IsEqualGUID(&
type->formattype, &FORMAT_WaveFormatEx)) {
718 fx = (
void *)
type->pbFormat;
735 fmt_info->
width = bih->biWidth;
736 fmt_info->
height = bih->biHeight;
746 if (extended_format_info) {
766 if ((hr = IAMStreamConfig_GetFormat(config,
type)) != S_OK) {
767 if (hr == E_NOTIMPL || !IsEqualGUID(&(*type)->majortype,
devtype ==
VideoDevice ? &MEDIATYPE_Video : &MEDIATYPE_Audio)) {
771 IEnumMediaTypes* types =
NULL;
772 if (IPin_EnumMediaTypes(pin, &types) != S_OK)
774 IEnumMediaTypes_Reset(types);
775 while (IEnumMediaTypes_Next(types, 1,
type,
NULL) == S_OK) {
776 if (IsEqualGUID(&(*type)->majortype,
devtype ==
VideoDevice ? &MEDIATYPE_Video : &MEDIATYPE_Audio)) {
779 CoTaskMemFree(*
type);
782 IEnumMediaTypes_Release(types);
796 IPin *pin,
int *pformat_set)
799 IAMStreamConfig *config =
NULL;
801 AM_MEDIA_TYPE *previous_match_type =
NULL;
805 int wait_for_better = 0;
812 enum AVCodecID requested_video_codec_id =
ctx->video_codec_id;
815 /
ctx->requested_framerate.num : 0;
819 int requested_sample_rate =
ctx->sample_rate;
820 int requested_sample_size =
ctx->sample_size;
821 int requested_channels =
ctx->channels;
823 if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (
void **) &config) != S_OK)
825 if (IAMStreamConfig_GetNumberOfCapabilities(config, &n, &
size) != S_OK)
840 if (use_default && pformat_set)
853 requested_video_codec_id = fmt_info->
codec_id;
854 requested_pixel_format = fmt_info->
pix_fmt;
855 requested_framerate = fmt_info->
framerate;
856 requested_width = fmt_info->
width;
857 requested_height = fmt_info->
height;
861 requested_channels = fmt_info->
channels;
867 CoTaskMemFree(
type->pbFormat);
886 for (
i = 0;
i < n && !format_set;
i++) {
888 r = IAMStreamConfig_GetStreamCaps(config,
i, &
type, (
void *) caps);
900 VIDEO_STREAM_CONFIG_CAPS *vcaps = caps;
901 BITMAPINFOHEADER *bih =
NULL;
910 if (IsEqualGUID(&
type->formattype, &FORMAT_VideoInfo)) {
911 VIDEOINFOHEADER *v = (
void *)
type->pbFormat;
912 fr = &v->AvgTimePerFrame;
915 }
else if (IsEqualGUID(&
type->formattype, &FORMAT_VideoInfo2)) {
916 VIDEOINFOHEADER2 *v = (
void *)
type->pbFormat;
917 fr = &v->AvgTimePerFrame;
927 av_log(avctx,
AV_LOG_INFO,
" unknown compression type 0x%X", (
int) bih->biCompression);
935 vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy,
936 1e7 / vcaps->MaxFrameInterval,
937 vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy,
938 1e7 / vcaps->MinFrameInterval);
951 prim ? prim :
"unknown",
952 trc ? trc :
"unknown");
964 if (requested_video_codec_id != fmt_info->
codec_id)
968 requested_pixel_format != fmt_info->
pix_fmt) {
971 if (requested_framerate) {
972 if (requested_framerate > vcaps->MaxFrameInterval ||
973 requested_framerate < vcaps->MinFrameInterval)
975 *fr = requested_framerate;
977 if (requested_width && requested_height) {
978 if (requested_width > vcaps->MaxOutputSize.cx ||
979 requested_width < vcaps->MinOutputSize.cx ||
980 requested_height > vcaps->MaxOutputSize.cy ||
981 requested_height < vcaps->MinOutputSize.cy)
983 bih->biWidth = requested_width;
984 bih->biHeight = requested_height;
989 AUDIO_STREAM_CONFIG_CAPS *acaps = caps;
992 if (IsEqualGUID(&
type->formattype, &FORMAT_WaveFormatEx)) {
993 fx = (
void *)
type->pbFormat;
1001 " ch=%2u, bits=%2u, rate=%6lu\n",
1002 fx->nChannels, fx->wBitsPerSample, fx->nSamplesPerSec
1007 (requested_sample_rate && requested_sample_rate != fx->nSamplesPerSec) ||
1008 (requested_sample_size && requested_sample_size != fx->wBitsPerSample) ||
1009 (requested_channels && requested_channels != fx->nChannels )
1019 if (!wait_for_better) {
1020 if (IAMStreamConfig_SetFormat(config,
type) != S_OK)
1024 else if (!previous_match_type) {
1027 previous_match_type =
type;
1033 CoTaskMemFree(
type->pbFormat);
1034 CoTaskMemFree(
type);
1039 if (pformat_set && !format_set) {
1040 if (previous_match_type) {
1047 if (IAMStreamConfig_SetFormat(config, previous_match_type) == S_OK)
1050 else if (use_default) {
1055 if (IAMStreamConfig_SetFormat(config,
type) == S_OK)
1058 CoTaskMemFree(
type->pbFormat);
1059 CoTaskMemFree(
type);
1065 if (previous_match_type && previous_match_type->pbFormat)
1066 CoTaskMemFree(previous_match_type->pbFormat);
1067 CoTaskMemFree(previous_match_type);
1068 IAMStreamConfig_Release(config);
1071 *pformat_set = format_set;
1082 IAMBufferNegotiation *buffer_negotiation =
NULL;
1083 ALLOCATOR_PROPERTIES props = { -1, -1, -1, -1 };
1084 IAMStreamConfig *config =
NULL;
1088 if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (
void **) &config) != S_OK)
1090 if (IAMStreamConfig_GetFormat(config, &
type) != S_OK)
1092 if (!IsEqualGUID(&
type->formattype, &FORMAT_WaveFormatEx))
1095 props.cbBuffer = (((WAVEFORMATEX *)
type->pbFormat)->nAvgBytesPerSec)
1096 *
ctx->audio_buffer_size / 1000;
1098 if (IPin_QueryInterface(pin, &IID_IAMBufferNegotiation, (
void **) &buffer_negotiation) != S_OK)
1100 if (IAMBufferNegotiation_SuggestAllocatorProperties(buffer_negotiation, &props) != S_OK)
1106 if (buffer_negotiation)
1107 IAMBufferNegotiation_Release(buffer_negotiation);
1110 CoTaskMemFree(
type->pbFormat);
1111 CoTaskMemFree(
type);
1114 IAMStreamConfig_Release(config);
1124 ISpecifyPropertyPages *property_pages =
NULL;
1125 IUnknown *device_filter_iunknown =
NULL;
1127 FILTER_INFO filter_info = {0};
1128 CAUUID ca_guid = {0};
1130 hr = IBaseFilter_QueryInterface(
device_filter, &IID_ISpecifyPropertyPages, (
void **)&property_pages);
1135 hr = IBaseFilter_QueryFilterInfo(
device_filter, &filter_info);
1139 hr = IBaseFilter_QueryInterface(
device_filter, &IID_IUnknown, (
void **)&device_filter_iunknown);
1143 hr = ISpecifyPropertyPages_GetPages(property_pages, &ca_guid);
1147 hr = OleCreatePropertyFrame(
NULL, 0, 0, filter_info.achName, 1, &device_filter_iunknown, ca_guid.cElems,
1148 ca_guid.pElems, 0, 0,
NULL);
1157 ISpecifyPropertyPages_Release(property_pages);
1158 if (device_filter_iunknown)
1159 IUnknown_Release(device_filter_iunknown);
1160 if (filter_info.pGraph)
1161 IFilterGraph_Release(filter_info.pGraph);
1163 CoTaskMemFree(ca_guid.pElems);
1177 IEnumPins *pins = 0;
1182 const char *devtypename = (devtype ==
VideoDevice) ?
"video" :
"audio only";
1183 const char *sourcetypename = (sourcetype ==
VideoSourceDevice) ?
"video" :
"audio";
1187 int should_show_properties = (devtype ==
VideoDevice) ?
ctx->show_video_device_dialog :
ctx->show_audio_device_dialog;
1189 if (should_show_properties)
1200 devtypename, sourcetypename);
1203 while (!
device_pin && IEnumPins_Next(pins, 1, &pin,
NULL) == S_OK) {
1204 IKsPropertySet *p =
NULL;
1205 PIN_INFO info = {0};
1208 char *name_buf =
NULL;
1209 wchar_t *pin_id =
NULL;
1210 char *pin_buf =
NULL;
1211 char *desired_pin_name = devtype ==
VideoDevice ?
ctx->video_pin_name :
ctx->audio_pin_name;
1213 IPin_QueryPinInfo(pin, &info);
1214 IBaseFilter_Release(info.pFilter);
1216 if (info.dir != PINDIR_OUTPUT)
1218 if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (
void **) &p) != S_OK)
1220 if (IKsPropertySet_Get(p, &ROPSETID_Pin, AMPROPERTY_PIN_CATEGORY,
1223 if (!IsEqualGUID(&
category, &PIN_CATEGORY_CAPTURE))
1227 r = IPin_QueryId(pin, &pin_id);
1235 av_log(avctx,
AV_LOG_INFO,
" Pin \"%s\" (alternative pin name \"%s\")\n", name_buf, pin_buf);
1240 if (desired_pin_name) {
1241 if(strcmp(name_buf, desired_pin_name) && strcmp(pin_buf, desired_pin_name)) {
1243 name_buf, pin_buf, desired_pin_name);
1257 av_log(avctx,
AV_LOG_ERROR,
"unable to set audio buffer size %d to pin, using pin anyway...",
ctx->audio_buffer_size);
1267 IKsPropertySet_Release(p);
1273 CoTaskMemFree(pin_id);
1276 IEnumPins_Release(pins);
1285 "Could not find output pin from %s capture device.\n", devtypename);
1323 char *device_filter_unique_name =
NULL;
1328 ICaptureGraphBuilder2 *graph_builder2 =
NULL;
1331 IStream *ifile_stream =
NULL;
1332 IStream *ofile_stream =
NULL;
1333 IPersistStream *pers_stream =
NULL;
1336 const wchar_t *filter_name[2] = {
L"Audio capture filter",
L"Video capture filter" };
1339 if ( ((
ctx->audio_filter_load_file) && (strlen(
ctx->audio_filter_load_file)>0) && (sourcetype ==
AudioSourceDevice)) ||
1340 ((
ctx->video_filter_load_file) && (strlen(
ctx->video_filter_load_file)>0) && (sourcetype ==
VideoSourceDevice)) ) {
1342 char *filename =
NULL;
1345 filename =
ctx->audio_filter_load_file;
1347 filename =
ctx->video_filter_load_file;
1349 hr = SHCreateStreamOnFile ((LPCSTR) filename, STGM_READ, &ifile_stream);
1355 hr = OleLoadFromStream(ifile_stream, &IID_IBaseFilter, (
void **) &
device_filter);
1365 av_log(avctx,
AV_LOG_INFO,
"Capture filter loaded successfully from file \"%s\".\n", filename);
1373 if (
ctx->device_filter[otherDevType]) {
1376 if (!device_filter_unique_name || strcmp(device_filter_unique_name,
ctx->device_unique_name[otherDevType]) == 0) {
1377 av_log(avctx,
AV_LOG_DEBUG,
"reusing previous graph capture filter... %s\n", device_filter_unique_name);
1380 IBaseFilter_AddRef(
ctx->device_filter[otherDevType]);
1382 av_log(avctx,
AV_LOG_DEBUG,
"not reusing previous graph capture filter %s != %s\n", device_filter_unique_name,
ctx->device_unique_name[otherDevType]);
1387 ctx->device_unique_name [devtype] = device_filter_unique_name;
1409 if ( ((
ctx->audio_filter_save_file) && (strlen(
ctx->audio_filter_save_file)>0) && (sourcetype ==
AudioSourceDevice)) ||
1410 ((
ctx->video_filter_save_file) && (strlen(
ctx->video_filter_save_file)>0) && (sourcetype ==
VideoSourceDevice)) ) {
1413 char *filename =
NULL;
1416 filename =
ctx->audio_filter_save_file;
1418 filename =
ctx->video_filter_save_file;
1420 hr = SHCreateStreamOnFile ((LPCSTR) filename, STGM_CREATE | STGM_READWRITE, &ofile_stream);
1426 hr = IBaseFilter_QueryInterface(
device_filter, &IID_IPersistStream, (
void **) &pers_stream);
1432 hr = OleSaveToStream(pers_stream, ofile_stream);
1438 hr = IStream_Commit(ofile_stream, STGC_DEFAULT);
1448 av_log(avctx,
AV_LOG_INFO,
"Capture filter saved successfully to file \"%s\".\n", filename);
1452 filter_name[devtype]);
1462 r = CoCreateInstance(&CLSID_CaptureGraphBuilder2,
NULL, CLSCTX_INPROC_SERVER,
1463 &IID_ICaptureGraphBuilder2, (
void **) &graph_builder2);
1468 r = ICaptureGraphBuilder2_SetFiltergraph(graph_builder2,
graph);
1492 if (graph_builder2 !=
NULL)
1493 ICaptureGraphBuilder2_Release(graph_builder2);
1496 IPersistStream_Release(pers_stream);
1499 IStream_Release(ifile_stream);
1502 IStream_Release(ofile_stream);
1509 switch (sample_fmt) {
1561 BITMAPINFOHEADER *bih =
NULL;
1564 if (IsEqualGUID(&
type.formattype, &FORMAT_VideoInfo)) {
1565 VIDEOINFOHEADER *v = (
void *)
type.pbFormat;
1566 time_base = (
AVRational) { v->AvgTimePerFrame, 10000000 };
1567 bih = &v->bmiHeader;
1568 }
else if (IsEqualGUID(&
type.formattype, &FORMAT_VideoInfo2)) {
1569 VIDEOINFOHEADER2 *v = (
void *)
type.pbFormat;
1570 time_base = (
AVRational) { v->AvgTimePerFrame, 10000000 };
1571 bih = &v->bmiHeader;
1586 if (bih->biCompression ==
MKTAG(
'H',
'D',
'Y',
'C')) {
1597 if (bih->biCompression == BI_RGB || bih->biCompression == BI_BITFIELDS) {
1612 "Please report type 0x%X.\n", (
int) bih->biCompression);
1619 if (!IsEqualGUID(&
type.formattype, &FORMAT_WaveFormatEx)) {
1638 CoTaskMemFree(
type.pbFormat);
1651 while ((
type = strtok(
tmp,
"="))) {
1652 char *token = strtok(
NULL,
":");
1655 if (!strcmp(
type,
"video")) {
1657 }
else if (!strcmp(
type,
"audio")) {
1683 ICreateDevEnum *devenum =
NULL;
1686 HANDLE media_event_handle;
1703 "video codec is not set or set to rawvideo\n");
1708 if (
ctx->framerate) {
1716 r = CoCreateInstance(&CLSID_FilterGraph,
NULL, CLSCTX_INPROC_SERVER,
1717 &IID_IGraphBuilder, (
void **) &
graph);
1724 r = CoCreateInstance(&CLSID_SystemDeviceEnum,
NULL, CLSCTX_INPROC_SERVER,
1725 &IID_ICreateDevEnum, (
void **) &devenum);
1731 if (
ctx->list_devices) {
1737 if (
ctx->list_options) {
1773 if (
ctx->list_options) {
1778 ctx->curbufsize[0] = 0;
1779 ctx->curbufsize[1] = 0;
1786 if (!
ctx->event[1]) {
1791 r = IGraphBuilder_QueryInterface(
graph, &IID_IMediaControl, (
void **) &
control);
1798 r = IGraphBuilder_QueryInterface(
graph, &IID_IMediaEvent, (
void **) &
media_event);
1805 r = IMediaEvent_GetEventHandle(
media_event, (
void *) &media_event_handle);
1810 proc = GetCurrentProcess();
1811 r = DuplicateHandle(proc, media_event_handle, proc, &
ctx->event[0],
1812 0, 0, DUPLICATE_SAME_ACCESS);
1821 r = IMediaControl_GetState(
control, 0, &pfs);
1824 av_log(avctx,
AV_LOG_ERROR,
"Could not run graph (sometimes caused by a device already in use by other application)\n");
1833 ICreateDevEnum_Release(devenum);
1852 while (IMediaEvent_GetEvent(
media_event, &
code, &p1, &p2, 0) != E_ABORT) {
1871 ctx->pktl =
ctx->pktl->next;
1873 ctx->curbufsize[
pkt->stream_index] -=
pkt->size;
1875 ResetEvent(
ctx->event[1]);
1876 ReleaseMutex(
ctx->mutex);
1883 WaitForMultipleObjects(2,
ctx->event, 0, INFINITE);
1891#define OFFSET(x) offsetof(struct dshow_ctx, x)
1892#define DEC AV_OPT_FLAG_DECODING_PARAM
1924 .class_name =
"dshow indev",
1937 .priv_data_size =
sizeof(
struct dshow_ctx),
const FFInputFormat ff_dshow_demuxer
static AVFormatContext * ctx
Main libavdevice API header.
static int parse_device_name(AVFormatContext *s)
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
#define i(width, name, range_min, range_max)
static const AVClass dshow_class
static int dshow_check_event_queue(IMediaEvent *media_event)
Checks media events from DirectShow and returns -1 on error or EOF.
static int dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum, enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype)
List options for device with type devtype, source filter type sourcetype.
static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt)
static enum AVColorRange dshow_color_range(DXVA2_ExtendedFormat *fmt_info)
static int dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype, IBaseFilter *device_filter, IPin **ppin)
Cycle through available pins using the device_filter device, of type devtype, retrieve the first outp...
static int dshow_get_device_list(AVFormatContext *avctx, AVDeviceInfoList *device_list)
#define AMCONTROL_COLORINFO_PRESENT
static enum AVColorPrimaries dshow_color_primaries(DXVA2_ExtendedFormat *fmt_info)
static enum AVPixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount)
static int dshow_should_set_format(AVFormatContext *avctx, enum dshowDeviceType devtype)
static int dshow_set_audio_buffer_size(AVFormatContext *avctx, IPin *pin)
Set audio device buffer size in milliseconds (which can directly impact latency, depending on the dev...
static char * dup_wchar_to_utf8(wchar_t *w)
static int dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype)
static enum AVSampleFormat sample_fmt_bits_per_sample(int bits)
static int dshow_add_device(AVFormatContext *avctx, enum dshowDeviceType devtype)
static enum AVCodecID waveform_codec_id(enum AVSampleFormat sample_fmt)
static int shall_we_drop(AVFormatContext *s, int index, enum dshowDeviceType devtype)
static enum AVColorTransferCharacteristic dshow_color_trc(DXVA2_ExtendedFormat *fmt_info)
static enum AVChromaLocation dshow_chroma_loc(DXVA2_ExtendedFormat *fmt_info)
static void dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, IPin *pin, int *pformat_set)
Cycle through available formats available from the specified pin, try to set parameters specified thr...
static enum AVColorSpace dshow_color_space(DXVA2_ExtendedFormat *fmt_info)
static int dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype, IBaseFilter **pfilter, char **device_unique_name, AVDeviceInfoList **device_list)
Cycle through available devices using the device enumerator devenum, retrieve the device with type sp...
static int parse_device_name(AVFormatContext *avctx)
static void dshow_get_device_media_types(AVFormatContext *avctx, enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype, IBaseFilter *device_filter, enum AVMediaType **media_types, int *nb_media_types)
void ff_dshow_show_filter_properties(IBaseFilter *device_filter, AVFormatContext *avctx)
Pops up a user dialog allowing them to adjust properties for the given filter, if possible.
static void dshow_get_default_format(IPin *pin, IAMStreamConfig *config, enum dshowDeviceType devtype, AM_MEDIA_TYPE **type)
static void callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, enum dshowDeviceType devtype)
static int dshow_read_close(AVFormatContext *s)
static int dshow_read_header(AVFormatContext *avctx)
static struct dshow_format_info * dshow_get_format_info(AM_MEDIA_TYPE *type)
void ff_print_VIDEO_STREAM_CONFIG_CAPS(const VIDEO_STREAM_CONFIG_CAPS *caps)
unsigned long WINAPI ff_dshow_pin_Release(DShowPin *)
void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type)
DShowFilter * ff_dshow_filter_Create(void *, void *, enum dshowDeviceType)
HRESULT ff_dshow_try_setup_crossbar_options(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, enum dshowDeviceType devtype, AVFormatContext *avctx)
Given a fully constructed graph, check if there is a cross bar filter, and configure its pins if so.
void ff_print_AUDIO_STREAM_CONFIG_CAPS(const AUDIO_STREAM_CONFIG_CAPS *caps)
long WINAPI ff_dshow_pin_ConnectionMediaType(DShowPin *, AM_MEDIA_TYPE *)
unsigned long WINAPI ff_dshow_pin_AddRef(DShowPin *)
unsigned long WINAPI ff_dshow_filter_Release(DShowFilter *)
static const uint8_t bits[8]
static int read_header(FFV1Context *f, RangeCoder *c)
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
@ AV_OPT_TYPE_PIXEL_FMT
Underlying C type is enum AVPixelFormat.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
enum AVCodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the AVCodecID for the given codec tag tag.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S32
signed 32 bits
@ AV_SAMPLE_FMT_U8
unsigned 8 bits
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define LIBAVUTIL_VERSION_INT
const struct AVCodecTag * avformat_get_riff_video_tags(void)
const char * friendly_name
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT
#define MKTAG(a, b, c, d)
Memory handling functions.
static int set_format(void *obj, const char *name, int fmt, int search_flags, enum AVOptionType type, const char *desc, int nb_fmts)
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
const char * av_color_space_name(enum AVColorSpace space)
const char * av_color_range_name(enum AVColorRange range)
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
const char * av_chroma_location_name(enum AVChromaLocation location)
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
#define AV_PIX_FMT_0RGB32
AVChromaLocation
Location of chroma samples.
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
@ AVCHROMA_LOC_UNSPECIFIED
AVColorRange
Visual content value range.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_JPEG
Full range content.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_RGB8
packed RGB 3:3:2, 8bpp, (msb)3R 3G 2B(lsb)
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_RGB4
packed RGB 1:2:1 bitstream, 4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in ...
@ AV_PIX_FMT_MONOWHITE
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb.
AVColorPrimaries
Chromaticity coordinates of the source primaries.
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
@ AVCOL_PRI_SMPTE240M
identical to above, also called "SMPTE C" even though it uses D65
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
@ AVCOL_PRI_SMPTE428
SMPTE ST 428-1 (CIE 1931 XYZ)
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
@ AVCOL_PRI_BT2020
ITU-R BT2020.
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
AVColorTransferCharacteristic
Color Transfer Characteristic.
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
@ AVCOL_TRC_LOG
"Logarithmic transfer characteristic (100:1 range)"
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
@ AVCOL_TRC_LOG_SQRT
"Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range)"
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
@ AVCOL_TRC_BT709
also ITU-R BT1361
#define AV_PIX_FMT_RGB555
AVColorSpace
YUV colorspace type.
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
enum AVPixelFormat avpriv_pix_fmt_find(enum PixelFormatTagLists list, unsigned fourcc)
internal header for RIFF based (de)muxers do NOT include this in end user applications
#define FF_ARRAY_ELEMS(a)
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
This struct describes the properties of an encoded stream.
enum AVColorSpace color_space
int extradata_size
Size of the extradata content in bytes.
int height
The height of the video frame in pixels.
int bits_per_coded_sample
The number of bits per sample in the codedwords.
AVChannelLayout ch_layout
The channel layout and number of channels.
int width
The width of the video frame in pixels.
enum AVMediaType codec_type
General type of the encoded data.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
enum AVColorPrimaries color_primaries
int sample_rate
The number of audio samples per second.
enum AVColorTransferCharacteristic color_trc
enum AVChromaLocation chroma_location
enum AVColorRange color_range
Additional colorspace characteristics.
const char * name
Name of the codec implementation.
Structure describes basic parameters of the device.
char * device_description
human friendly name
enum AVMediaType * media_types
array indicating what media types(s), if any, a device can provide.
int nb_media_types
length of media_types array, 0 if device cannot provide any media types
char * device_name
device name, format depends on device
char * url
input or output URL.
enum AVCodecID video_codec_id
Forced video codec_id.
void * priv_data
Format private data.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int id
Format-specific stream ID.
int index
stream index in AVFormatContext
AVRational avg_frame_rate
Average framerate.
AVRational r_frame_rate
Real base framerate of the stream.
struct PacketListEntry * next
IMediaEvent * media_event
int show_video_device_dialog
char * audio_filter_save_file
int crossbar_audio_input_pin_number
int show_analog_tv_tuner_audio_dialog
int show_analog_tv_tuner_dialog
char * audio_filter_load_file
int show_video_crossbar_connection_dialog
AVRational requested_framerate
int show_audio_device_dialog
int show_audio_crossbar_connection_dialog
char * video_filter_load_file
char * video_filter_save_file
int crossbar_video_input_pin_number
DShowPin * capture_pin[2]
char * device_unique_name[2]
enum AVPixelFormat pixel_format
int use_video_device_timestamps
IBaseFilter * device_filter[2]
DShowFilter * capture_filter[2]
#define av_malloc_array(a, b)
static void error(const char *err)
#define WaitForSingleObject(a, b)