FFmpeg
Data Structures | Macros | Functions | Variables
dshow.c File Reference
#include "dshow_capture.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
#include "libavutil/opt.h"
#include "libavutil/mem.h"
#include "libavformat/demux.h"
#include "libavformat/internal.h"
#include "libavformat/riff.h"
#include "avdevice.h"
#include "libavcodec/raw.h"
#include "objidl.h"
#include "shlwapi.h"
#include "d3d9types.h"
#include "dxva2api.h"

Go to the source code of this file.

Data Structures

struct  dshow_format_info
 

Macros

#define AMCONTROL_COLORINFO_PRESENT   0x00000080
 
#define OFFSET(x)   offsetof(struct dshow_ctx, x)
 
#define DEC   AV_OPT_FLAG_DECODING_PARAM
 

Functions

static enum AVPixelFormat dshow_pixfmt (DWORD biCompression, WORD biBitCount)
 
static enum AVColorRange dshow_color_range (DXVA2_ExtendedFormat *fmt_info)
 
static enum AVColorSpace dshow_color_space (DXVA2_ExtendedFormat *fmt_info)
 
static enum AVColorPrimaries dshow_color_primaries (DXVA2_ExtendedFormat *fmt_info)
 
static enum AVColorTransferCharacteristic dshow_color_trc (DXVA2_ExtendedFormat *fmt_info)
 
static enum AVChromaLocation dshow_chroma_loc (DXVA2_ExtendedFormat *fmt_info)
 
static int dshow_read_close (AVFormatContext *s)
 
static char * dup_wchar_to_utf8 (wchar_t *w)
 
static int shall_we_drop (AVFormatContext *s, int index, enum dshowDeviceType devtype)
 
static void callback (void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, enum dshowDeviceType devtype)
 
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)
 
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 specified by devtype and return the pointer to the object found in *pfilter. More...
 
static int dshow_get_device_list (AVFormatContext *avctx, AVDeviceInfoList *device_list)
 
static int dshow_should_set_format (AVFormatContext *avctx, enum dshowDeviceType devtype)
 
static struct dshow_format_infodshow_get_format_info (AM_MEDIA_TYPE *type)
 
static void dshow_get_default_format (IPin *pin, IAMStreamConfig *config, enum dshowDeviceType devtype, AM_MEDIA_TYPE **type)
 
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 through AVOptions, or the pin's default format if no such parameters were set. More...
 
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 device). More...
 
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. More...
 
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 output pin and return the pointer to the object found in *ppin. More...
 
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. More...
 
static int dshow_open_device (AVFormatContext *avctx, ICreateDevEnum *devenum, enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype)
 
static enum AVCodecID waveform_codec_id (enum AVSampleFormat sample_fmt)
 
static enum AVSampleFormat sample_fmt_bits_per_sample (int bits)
 
static int dshow_add_device (AVFormatContext *avctx, enum dshowDeviceType devtype)
 
static int parse_device_name (AVFormatContext *avctx)
 
static int dshow_read_header (AVFormatContext *avctx)
 
static int dshow_check_event_queue (IMediaEvent *media_event)
 Checks media events from DirectShow and returns -1 on error or EOF. More...
 
static int dshow_read_packet (AVFormatContext *s, AVPacket *pkt)
 

Variables

static const AVOption options []
 
static const AVClass dshow_class
 
const FFInputFormat ff_dshow_demuxer
 

Macro Definition Documentation

◆ AMCONTROL_COLORINFO_PRESENT

#define AMCONTROL_COLORINFO_PRESENT   0x00000080

Definition at line 56 of file dshow.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(struct dshow_ctx, x)

Definition at line 1891 of file dshow.c.

◆ DEC

#define DEC   AV_OPT_FLAG_DECODING_PARAM

Definition at line 1892 of file dshow.c.

Function Documentation

◆ dshow_pixfmt()

static enum AVPixelFormat dshow_pixfmt ( DWORD  biCompression,
WORD  biBitCount 
)
static

Definition at line 60 of file dshow.c.

Referenced by dshow_get_format_info().

◆ dshow_color_range()

static enum AVColorRange dshow_color_range ( DXVA2_ExtendedFormat *  fmt_info)
static

Definition at line 83 of file dshow.c.

Referenced by dshow_get_format_info().

◆ dshow_color_space()

static enum AVColorSpace dshow_color_space ( DXVA2_ExtendedFormat *  fmt_info)
static

Definition at line 107 of file dshow.c.

Referenced by dshow_get_format_info().

◆ dshow_color_primaries()

static enum AVColorPrimaries dshow_color_primaries ( DXVA2_ExtendedFormat *  fmt_info)
static

Definition at line 131 of file dshow.c.

Referenced by dshow_get_format_info().

◆ dshow_color_trc()

static enum AVColorTransferCharacteristic dshow_color_trc ( DXVA2_ExtendedFormat *  fmt_info)
static

Definition at line 168 of file dshow.c.

Referenced by dshow_get_format_info().

◆ dshow_chroma_loc()

static enum AVChromaLocation dshow_chroma_loc ( DXVA2_ExtendedFormat *  fmt_info)
static

Definition at line 223 of file dshow.c.

Referenced by dshow_get_format_info().

◆ dshow_read_close()

static int dshow_read_close ( AVFormatContext s)
static

Definition at line 239 of file dshow.c.

Referenced by dshow_read_header().

◆ dup_wchar_to_utf8()

static char* dup_wchar_to_utf8 ( wchar_t *  w)
static

Definition at line 313 of file dshow.c.

Referenced by dshow_cycle_pins().

◆ shall_we_drop()

static int shall_we_drop ( AVFormatContext s,
int  index,
enum dshowDeviceType  devtype 
)
static

Definition at line 323 of file dshow.c.

Referenced by callback().

◆ callback()

static void callback ( void *  priv_data,
int  index,
uint8_t *  buf,
int  buf_size,
int64_t  time,
enum dshowDeviceType  devtype 
)
static

◆ dshow_get_device_media_types()

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 
)
static

Definition at line 382 of file dshow.c.

◆ dshow_cycle_devices()

static int dshow_cycle_devices ( AVFormatContext avctx,
ICreateDevEnum *  devenum,
enum dshowDeviceType  devtype,
enum dshowSourceFilterType  sourcetype,
IBaseFilter **  pfilter,
char **  device_unique_name,
AVDeviceInfoList **  device_list 
)
static

Cycle through available devices using the device enumerator devenum, retrieve the device with type specified by devtype and return the pointer to the object found in *pfilter.

If pfilter is NULL, list all device names. If device_list is not NULL, populate it with found devices instead of outputting device names to log

Definition at line 463 of file dshow.c.

Referenced by dshow_get_device_list(), dshow_list_device_options(), dshow_open_device(), and dshow_read_header().

◆ dshow_get_device_list()

static int dshow_get_device_list ( AVFormatContext avctx,
AVDeviceInfoList device_list 
)
static

Definition at line 629 of file dshow.c.

◆ dshow_should_set_format()

static int dshow_should_set_format ( AVFormatContext avctx,
enum dshowDeviceType  devtype 
)
static

Definition at line 661 of file dshow.c.

Referenced by dshow_cycle_formats(), and dshow_cycle_pins().

◆ dshow_get_format_info()

static struct dshow_format_info* dshow_get_format_info ( AM_MEDIA_TYPE *  type)
static

Definition at line 693 of file dshow.c.

Referenced by dshow_add_device(), and dshow_cycle_formats().

◆ dshow_get_default_format()

static void dshow_get_default_format ( IPin *  pin,
IAMStreamConfig *  config,
enum dshowDeviceType  devtype,
AM_MEDIA_TYPE **  type 
)
static

Definition at line 762 of file dshow.c.

Referenced by dshow_cycle_formats().

◆ dshow_cycle_formats()

static void dshow_cycle_formats ( AVFormatContext avctx,
enum dshowDeviceType  devtype,
IPin *  pin,
int pformat_set 
)
static

Cycle through available formats available from the specified pin, try to set parameters specified through AVOptions, or the pin's default format if no such parameters were set.

If successful, return 1 in *pformat_set. If pformat_set is NULL, list all pin capabilities.

If we should open the device with the default format, then:

  1. check what the format of the default device is, and
  2. below we iterate all formats till we find a matching one, with most info exposed (see comment below).

Definition at line 795 of file dshow.c.

Referenced by dshow_cycle_pins().

◆ dshow_set_audio_buffer_size()

static int dshow_set_audio_buffer_size ( AVFormatContext avctx,
IPin *  pin 
)
static

Set audio device buffer size in milliseconds (which can directly impact latency, depending on the device).

Definition at line 1079 of file dshow.c.

Referenced by dshow_cycle_pins().

◆ ff_dshow_show_filter_properties()

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.

Definition at line 1123 of file dshow.c.

Referenced by dshow_cycle_pins(), and ff_dshow_try_setup_crossbar_options().

◆ dshow_cycle_pins()

static int dshow_cycle_pins ( AVFormatContext avctx,
enum dshowDeviceType  devtype,
enum dshowSourceFilterType  sourcetype,
IBaseFilter *  device_filter,
IPin **  ppin 
)
static

Cycle through available pins using the device_filter device, of type devtype, retrieve the first output pin and return the pointer to the object found in *ppin.

If ppin is NULL, cycle through all pins listing audio/video capabilities.

Definition at line 1173 of file dshow.c.

Referenced by dshow_list_device_options(), and dshow_open_device().

◆ dshow_list_device_options()

static int dshow_list_device_options ( AVFormatContext avctx,
ICreateDevEnum *  devenum,
enum dshowDeviceType  devtype,
enum dshowSourceFilterType  sourcetype 
)
static

List options for device with type devtype, source filter type sourcetype.

Parameters
devenumdevice enumerator used for accessing the device

Definition at line 1300 of file dshow.c.

Referenced by dshow_read_header().

◆ dshow_open_device()

static int dshow_open_device ( AVFormatContext avctx,
ICreateDevEnum *  devenum,
enum dshowDeviceType  devtype,
enum dshowSourceFilterType  sourcetype 
)
static

Definition at line 1318 of file dshow.c.

Referenced by dshow_read_header().

◆ waveform_codec_id()

static enum AVCodecID waveform_codec_id ( enum AVSampleFormat  sample_fmt)
static

Definition at line 1507 of file dshow.c.

Referenced by dshow_add_device().

◆ sample_fmt_bits_per_sample()

static enum AVSampleFormat sample_fmt_bits_per_sample ( int  bits)
static

Definition at line 1517 of file dshow.c.

Referenced by dshow_add_device().

◆ dshow_add_device()

static int dshow_add_device ( AVFormatContext avctx,
enum dshowDeviceType  devtype 
)
static

Definition at line 1528 of file dshow.c.

Referenced by dshow_read_header().

◆ parse_device_name()

static int parse_device_name ( AVFormatContext avctx)
static

Definition at line 1642 of file dshow.c.

Referenced by dshow_read_header().

◆ dshow_read_header()

static int dshow_read_header ( AVFormatContext avctx)
static

Definition at line 1679 of file dshow.c.

◆ dshow_check_event_queue()

static int dshow_check_event_queue ( IMediaEvent *  media_event)
static

Checks media events from DirectShow and returns -1 on error or EOF.

Also purges all events that might be in the event queue to stop the trigger of event notification.

Definition at line 1846 of file dshow.c.

Referenced by dshow_read_packet().

◆ dshow_read_packet()

static int dshow_read_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 1861 of file dshow.c.

Variable Documentation

◆ options

const AVOption options[]
static
Initial value:
= {
{ "video_size", "set video size given a string such as 640x480 or hd720.", OFFSET(requested_width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
{ "pixel_format", "set video pixel format", OFFSET(pixel_format), AV_OPT_TYPE_PIXEL_FMT, {.i64 = AV_PIX_FMT_NONE}, -1, INT_MAX, DEC },
{ "framerate", "set video frame rate", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
{ "sample_rate", "set audio sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
{ "sample_size", "set audio sample size", OFFSET(sample_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 16, DEC },
{ "channels", "set number of audio channels, such as 1 or 2", OFFSET(channels), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
{ "audio_buffer_size", "set audio device buffer latency size in milliseconds (default is the device's default)", OFFSET(audio_buffer_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
{ "list_devices", "list available devices", OFFSET(list_devices), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, DEC },
{ "list_options", "list available options for specified device", OFFSET(list_options), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, DEC },
{ "video_device_number", "set video device number for devices with same name (starts at 0)", OFFSET(video_device_number), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
{ "audio_device_number", "set audio device number for devices with same name (starts at 0)", OFFSET(audio_device_number), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
{ "video_pin_name", "select video capture pin by name", OFFSET(video_pin_name),AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
{ "audio_pin_name", "select audio capture pin by name", OFFSET(audio_pin_name),AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
{ "crossbar_video_input_pin_number", "set video input pin number for crossbar device", OFFSET(crossbar_video_input_pin_number), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, DEC },
{ "crossbar_audio_input_pin_number", "set audio input pin number for crossbar device", OFFSET(crossbar_audio_input_pin_number), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, DEC },
{ "show_video_device_dialog", "display property dialog for video capture device", OFFSET(show_video_device_dialog), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
{ "show_audio_device_dialog", "display property dialog for audio capture device", OFFSET(show_audio_device_dialog), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
{ "show_video_crossbar_connection_dialog", "display property dialog for crossbar connecting pins filter on video device", OFFSET(show_video_crossbar_connection_dialog), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
{ "show_audio_crossbar_connection_dialog", "display property dialog for crossbar connecting pins filter on audio device", OFFSET(show_audio_crossbar_connection_dialog), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
{ "show_analog_tv_tuner_dialog", "display property dialog for analog tuner filter", OFFSET(show_analog_tv_tuner_dialog), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
{ "show_analog_tv_tuner_audio_dialog", "display property dialog for analog tuner audio filter", OFFSET(show_analog_tv_tuner_audio_dialog), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
{ "audio_device_load", "load audio capture filter device (and properties) from file", OFFSET(audio_filter_load_file), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
{ "audio_device_save", "save audio capture filter device (and properties) to file", OFFSET(audio_filter_save_file), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
{ "video_device_load", "load video capture filter device (and properties) from file", OFFSET(video_filter_load_file), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
{ "video_device_save", "save video capture filter device (and properties) to file", OFFSET(video_filter_save_file), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
{ "use_video_device_timestamps", "use device instead of wallclock timestamps for video frames", OFFSET(use_video_device_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DEC },
{ NULL },
}

Definition at line 1893 of file dshow.c.

◆ dshow_class

const AVClass dshow_class
static
Initial value:
= {
.class_name = "dshow indev",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 1923 of file dshow.c.

◆ ff_dshow_demuxer

const FFInputFormat ff_dshow_demuxer
Initial value:
= {
.p.name = "dshow",
.p.long_name = NULL_IF_CONFIG_SMALL("DirectShow capture"),
.p.priv_class = &dshow_class,
.priv_data_size = sizeof(struct dshow_ctx),
.read_packet = dshow_read_packet,
.read_close = dshow_read_close,
.get_device_list= dshow_get_device_list,
}

Definition at line 1931 of file dshow.c.

AVFMT_NO_BYTE_SEEK
#define AVFMT_NO_BYTE_SEEK
Format does not allow seeking by bytes.
Definition: avformat.h:487
DEC
#define DEC
Definition: dshow.c:1892
dshow_read_close
static int dshow_read_close(AVFormatContext *s)
Definition: dshow.c:239
dshow_class
static const AVClass dshow_class
Definition: dshow.c:1923
AVFMT_NOBINSEARCH
#define AVFMT_NOBINSEARCH
Format does not allow to fall back on binary search via read_timestamp.
Definition: avformat.h:485
sample_rate
sample_rate
Definition: ffmpeg_filter.c:409
dshow_read_header
static int dshow_read_header(AVFormatContext *avctx)
Definition: dshow.c:1679
dshow_ctx
Definition: dshow_capture.h:287
dshow_get_device_list
static int dshow_get_device_list(AVFormatContext *avctx, AVDeviceInfoList *device_list)
Definition: dshow.c:629
dshow_read_packet
static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: dshow.c:1861
channels
channels
Definition: aptx.h:31
framerate
float framerate
Definition: av1_levels.c:29
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:550
NULL
#define NULL
Definition: coverity.c:32
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:245
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT
@ AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT
Definition: log.h:41
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition: opt.h:269
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:468
options
static const AVOption options[]
Definition: dshow.c:1893
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
AVFMT_NOGENSEARCH
#define AVFMT_NOGENSEARCH
Format does not allow to fall back on generic search.
Definition: avformat.h:486
AV_OPT_TYPE_PIXEL_FMT
@ AV_OPT_TYPE_PIXEL_FMT
Definition: opt.h:246
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:251
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:239
OFFSET
#define OFFSET(x)
Definition: dshow.c:1891