From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH v5 13/13] avdevice/dshow: select format with extended color info
Date: Mon, 20 Dec 2021 02:32:43 +0100
Message-ID: <AM7PR03MB6660C2C6A759DC3762CDFFD68F7B9@AM7PR03MB6660.eurprd03.prod.outlook.com> (raw)
In-Reply-To: <20211219192134.1296-14-dcnieho@gmail.com>
Diederick Niehorster:
> Some DirectShow devices (Logitech C920 webcam) expose each DirectShow
> format they support twice, once without and once with extended color
> information. During format selection, both match, this patch ensures
> that the format with extended color information is selected if it is
> available, else it falls back to a matching format without such
> information. This also necessitated a new code path taken for default
> formats of a device (when user didn't request any specific video size,
> etc), because the default format may be one without extended color
> information when a twin with extended color information is also
> available. Getting the extended color information when available is
> important as it allows setting the color space, range, primaries,
> transfer characteristics and chroma location of the stream provided by
> dshow, enabling users to get more correct color automatically out of
> their device.
>
> Closes: #9271
>
> Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
> ---
> libavdevice/dshow.c | 469 +++++++++++++++++++++++++++++++-------------
> 1 file changed, 338 insertions(+), 131 deletions(-)
>
[...]
> @@ -1342,6 +1556,7 @@ dshow_add_device(AVFormatContext *avctx,
> AM_MEDIA_TYPE type;
> AVCodecParameters *par;
> AVStream *st;
> + struct dshow_format_info *fmt_info = NULL;
> int ret = AVERROR(EIO);
>
> type.pbFormat = NULL;
> @@ -1356,12 +1571,14 @@ dshow_add_device(AVFormatContext *avctx,
> ctx->capture_filter[devtype]->stream_index = st->index;
>
> ff_dshow_pin_ConnectionMediaType(ctx->capture_pin[devtype], &type);
> + fmt_info = dshow_get_format_info(&type);
> + if (!fmt_info)
> + goto error;
It is dangerous to goto error without setting ret to an error; it might
work now due to the ret = AVERROR(EIO) initialization, but it is
nevertheless dangerous.
>
> par = st->codecpar;
> if (devtype == VideoDevice) {
> BITMAPINFOHEADER *bih = NULL;
> AVRational time_base;
> - DXVA2_ExtendedFormat *extended_format_info = NULL;
>
> if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo)) {
> VIDEOINFOHEADER *v = (void *) type.pbFormat;
> @@ -1371,8 +1588,6 @@ dshow_add_device(AVFormatContext *avctx,
> VIDEOINFOHEADER2 *v = (void *) type.pbFormat;
> time_base = (AVRational) { v->AvgTimePerFrame, 10000000 };
> bih = &v->bmiHeader;
> - if (v->dwControlFlags & AMCONTROL_COLORINFO_PRESENT)
> - extended_format_info = (DXVA2_ExtendedFormat *) &v->dwControlFlags;
> }
> if (!bih) {
> av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n");
> @@ -1383,33 +1598,21 @@ dshow_add_device(AVFormatContext *avctx,
> st->r_frame_rate = av_inv_q(time_base);
>
> par->codec_type = AVMEDIA_TYPE_VIDEO;
> - par->width = bih->biWidth;
> - par->height = bih->biHeight;
> + par->width = fmt_info->width;
> + par->height = fmt_info->height;
> par->codec_tag = bih->biCompression;
> - par->format = dshow_pixfmt(bih->biCompression, bih->biBitCount);
> + par->format = fmt_info->pix_fmt;
> if (bih->biCompression == MKTAG('H', 'D', 'Y', 'C')) {
> av_log(avctx, AV_LOG_DEBUG, "attempt to use full range for HDYC...\n");
> par->color_range = AVCOL_RANGE_MPEG; // just in case it needs this...
> }
> - if (extended_format_info) {
> - par->color_range = dshow_color_range(extended_format_info);
> - par->color_space = dshow_color_space(extended_format_info);
> - par->color_primaries = dshow_color_primaries(extended_format_info);
> - par->color_trc = dshow_color_trc(extended_format_info);
> - par->chroma_location = dshow_chroma_loc(extended_format_info);
> - }
> - if (par->format == AV_PIX_FMT_NONE) {
> - const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL };
> - par->codec_id = av_codec_get_id(tags, bih->biCompression);
> - if (par->codec_id == AV_CODEC_ID_NONE) {
> - av_log(avctx, AV_LOG_ERROR, "Unknown compression type. "
> - "Please report type 0x%X.\n", (int) bih->biCompression);
> - ret = AVERROR_PATCHWELCOME;
> - goto error;
> - }
> - par->bits_per_coded_sample = bih->biBitCount;
> - } else {
> - par->codec_id = AV_CODEC_ID_RAWVIDEO;
> + par->color_range = fmt_info->col_range;
> + par->color_space = fmt_info->col_space;
> + par->color_primaries = fmt_info->col_prim;
> + par->color_trc = fmt_info->col_trc;
> + par->chroma_location = fmt_info->chroma_loc;
> + par->codec_id = fmt_info->codec_id;
> + if (par->codec_id == AV_CODEC_ID_RAWVIDEO) {
> if (bih->biCompression == BI_RGB || bih->biCompression == BI_BITFIELDS) {
> par->bits_per_coded_sample = bih->biBitCount;
> if (par->height < 0) {
> @@ -1422,23 +1625,26 @@ dshow_add_device(AVFormatContext *avctx,
> }
> }
> }
> + } else {
> + if (par->codec_id == AV_CODEC_ID_NONE) {
> + av_log(avctx, AV_LOG_ERROR, "Unknown compression type. "
> + "Please report type 0x%X.\n", (int) bih->biCompression);
> + ret = AVERROR_PATCHWELCOME;
> + goto error;
> + }
> + par->bits_per_coded_sample = bih->biBitCount;
> }
> } else {
> - WAVEFORMATEX *fx = NULL;
> -
> - if (IsEqualGUID(&type.formattype, &FORMAT_WaveFormatEx)) {
> - fx = (void *) type.pbFormat;
> - }
> - if (!fx) {
> + if (!IsEqualGUID(&type.formattype, &FORMAT_WaveFormatEx)) {
> av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n");
> goto error;
> }
>
> par->codec_type = AVMEDIA_TYPE_AUDIO;
> - par->format = sample_fmt_bits_per_sample(fx->wBitsPerSample);
> + par->format = sample_fmt_bits_per_sample(fmt_info->sample_size);
> par->codec_id = waveform_codec_id(par->format);
> - par->sample_rate = fx->nSamplesPerSec;
> - par->channels = fx->nChannels;
> + par->sample_rate = fmt_info->sample_rate;
> + par->channels = fmt_info->channels;
> }
>
> avpriv_set_pts_info(st, 64, 1, 10000000);
> @@ -1446,6 +1652,7 @@ dshow_add_device(AVFormatContext *avctx,
> ret = 0;
>
> error:
> + av_freep(&fmt_info);
> if (type.pbFormat)
> CoTaskMemFree(type.pbFormat);
> return ret;
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
prev parent reply other threads:[~2021-12-20 1:32 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-19 19:21 [FFmpeg-devel] [PATCH v5 00/13] dshow enhancements Diederick Niehorster
2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 01/13] avdevice/dshow: prevent NULL access Diederick Niehorster
2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 02/13] avdevice/dshow: implement option to use device video timestamps Diederick Niehorster
2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 03/13] avdevice/dshow: add use_video_device_timestamps to docs Diederick Niehorster
2021-12-20 0:42 ` Andreas Rheinhardt
2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 04/13] avdevice/dshow: query graph and sample time only once Diederick Niehorster
2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 05/13] avdevice/dshow: handle unknown sample time Diederick Niehorster
2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 06/13] avdevice/dshow: set no-seek flags Diederick Niehorster
2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 07/13] avdevice/dshow: implement get_device_list Diederick Niehorster
2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 08/13] avdevice/dshow: list_devices: show media type(s) per device Diederick Niehorster
2021-12-20 0:55 ` Andreas Rheinhardt
2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 09/13] avdevice: add info about media types(s) to AVDeviceInfo Diederick Niehorster
2021-12-20 0:59 ` Andreas Rheinhardt
2021-12-20 9:54 ` Diederick C. Niehorster
2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 10/13] avdevice/dshow: add media type info to get_device_list Diederick Niehorster
2021-12-20 1:04 ` Andreas Rheinhardt
2021-12-20 8:01 ` Diederick C. Niehorster
2021-12-21 11:55 ` Diederick C. Niehorster
2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 11/13] fftools: provide media type info for devices Diederick Niehorster
2021-12-20 1:22 ` Andreas Rheinhardt
2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 12/13] avdevice/dshow: discover source color range/space/etc Diederick Niehorster
2021-12-20 1:27 ` Andreas Rheinhardt
2021-12-20 8:10 ` Diederick C. Niehorster
2021-12-19 19:21 ` [FFmpeg-devel] [PATCH v5 13/13] avdevice/dshow: select format with extended color info Diederick Niehorster
2021-12-20 1:32 ` Andreas Rheinhardt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AM7PR03MB6660C2C6A759DC3762CDFFD68F7B9@AM7PR03MB6660.eurprd03.prod.outlook.com \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git