From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 1AA2E4027E for ; Mon, 20 Dec 2021 01:32:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6D86068AEEA; Mon, 20 Dec 2021 03:32:52 +0200 (EET) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05olkn2045.outbound.protection.outlook.com [40.92.90.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4B15868A2EC for ; Mon, 20 Dec 2021 03:32:46 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EKypYwTq3lzlIOUGEtU4yp97cSEusNuFwFBvDwm6SQGL06rvjqMoYyTivho7jGYJ1YZyfVv2CXjt32AvkmxDjLqP5rmYIep8a15BZiKh6/j+sLgA1XsEdXls0BlAxG7ymo09t3o0C9kfVVhPdNb1xkcHZTlmBFqTXdAmWtShjtmSq2Gbnl5g3o4Rj59KGgvMGTTWMtxUmprX66AIARvH+r8dSUp0324m6d7TqBNrLvtikrpGFFzV6strCb0KKLFJKqOZ7y4ebaCudU+f/nomy5cL61aOKiXVENwlYEUhUmbVs1a1+dxQtRzjGMHoBJ4rTNMxgOUc4tAhxRYzVpBJXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LW7Qfpq4ykBAUXhxVrAdpoE/1QDxO9PgvMByWrBLZKk=; b=eTEtsHPYfy/SfyLSSDohH1a3kkb6VivZxqocriFVj/+BrVCviSN8RVNJcrPXl9OibAiZrKcTNA4yVbSpZokHx3HKuTVDqeElvnyQA7wjFWG1FCNn9iJ+z4xugYK3/f/jhLEtjnvUSLuZixSXRt9IFI/W56oJ09aJCpKfwJo0mycyyBlcbsR36uVRBf/xz/eQrZAumFSwzecSxPmGd9uhp7JliwuQmoGKhFnVYdinfsxCuryZ78lPUACPNhJu+1/dK7LVOfmK0ovyI9Hh9iIcVABqdDYem3rfz7V2RVAwITbee4oTWMMjCLIZbkQ7TER5Jcua+d3vCgnM+BY9iCXzww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LW7Qfpq4ykBAUXhxVrAdpoE/1QDxO9PgvMByWrBLZKk=; b=tz5KJ0gaVsdZjGonE+czm7oyKZnOuSuDtEpNUDU5lLWvTBm2oiOx+2jflzNsBpsbOZFG367+DAR1i2DfJ3E55ydcrWzgEQDCMvQBv6RLXqaUp5H2bdbYsNao2uYLC3DUPU9W5t6nXCkA0Tr1Z3tRVvAVoGAFvGp1PQZ/urvsmbmgyMrv1Ya9FzttB2cRAvheP3dlVOUpmoUb99Zie1TgF2Kqc3/Vfe/+6kU10u4i2sBhCFVonTRm/mP2+Yh77iGp53v4BKTMk3R2kUH1f6H4Be5r+dkl+T1i+uD/pJW7fV+vLreXbx5OMTp28YX9Y8pPFx3QtJjNOWgShcIw/hk0sw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM5PR03MB3011.eurprd03.prod.outlook.com (2603:10a6:206:17::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.15; Mon, 20 Dec 2021 01:32:44 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%6]) with mapi id 15.20.4801.020; Mon, 20 Dec 2021 01:32:44 +0000 Message-ID: Date: Mon, 20 Dec 2021 02:32:43 +0100 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20211219192134.1296-1-dcnieho@gmail.com> <20211219192134.1296-14-dcnieho@gmail.com> From: Andreas Rheinhardt In-Reply-To: <20211219192134.1296-14-dcnieho@gmail.com> X-TMN: [jijr399l9g1didDk4wxmc93kTIjxCKgP] X-ClientProxiedBy: AM9P193CA0027.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:21e::32) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <930e2fb7-8c1a-6fd8-f6a0-858086294e40@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 92797cd6-b67b-424e-e99e-08d9c3589f35 X-MS-TrafficTypeDiagnostic: AM5PR03MB3011:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: R5OxGhbWFqjPAJ4XvVcAV9cUAKb9iOCGL7IxMh0ayabGTGZkAKgDT//bT5Lg7/LOXGXLUQbD/EtIp57LnHOwWomKBV/AyYZ8WZr8q6xUZI0m6blQooZXLFSWnTCq+ssfNdRX/cTeQL/6Qit+yc69uGkcEeztg/4ZMmQq7Qp6lfBrFWQqERT7RA8kBPdLxQFTe1z7O1xMmQOCRNgnbMtgt5tGypnilI3KunQsXjCV29Se7W7rvQZZLhXidaPAari6SSnhrN5rIwyACk071+RG/ThHCIb6lKnRJmSXNstrrMcOCjihNY9bBkh0uN5eLy6YMBLSgCO5DpUDn4U6dourRDhG21LTrZmgvI8VNR2ErorOHnsFH9PunPIOnhlpVcQ8iD8F8bQk/3kPUusLOGOLMsehcwPYXz1LgEQyepNyAVlTYCPXEc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FKa1JVSlhVSE1LdFE0ME9k?= =?utf-8?B?NGdVallldml2RklNdXhpMG1MbWZmSVA1ZlpvbjNiMGdDem9wR0RoUDBEcUdw?= =?utf-8?B?dXBhRmtqWk1ZbFl0UkVUeUlmbHByOEp2ejlMcFhiTmQrWjQ4by9mMWY4RExK?= =?utf-8?B?NFAwT3gxRXp4VFFETVdGdmxjUVRNYS8yZ0NGb2VTOU91R0pRZFlDYWdSL2J1?= =?utf-8?B?TmR0SnMzblo2anE5Q2FUWlFad2xSQkZTVE1yYmczYmRkNXVvOFNYZEFzdWsx?= =?utf-8?B?TzlkTEtOd0FEaTJPbDZuL1BSL2hHTWh4VTBaRHl1ODMyTmRQd0VPTk5nMEtU?= =?utf-8?B?dkQyVFBQV3hQVFlHeXdaTDhnbHVXN3hrZGg4aUc1ZEw2NDd6L3dBMXoybHla?= =?utf-8?B?RFpGMmZ3VkphNnIzTmw4WmhQYVcxTllVR2pocTRyTURvdVhRUWRGMm80NytH?= =?utf-8?B?eVZPaGxQRHBYZ3R1cXNLNHl2YTZxVEdKSEthKzQzYll4a21NdE9ycWtVd2h4?= =?utf-8?B?b0kzNGVkMGgrK0c4MUgwUnZBSDduSVFqbEVMdkZUVFhETWxTR1hReUF4cjk3?= =?utf-8?B?SExIVGtiMGd4R1Q5OGtKN01qZW1iVkxOdWUxdVBsOU1HTlkvUT09?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 92797cd6-b67b-424e-e99e-08d9c3589f35 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Dec 2021 01:32:44.7014 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR03MB3011 Subject: Re: [FFmpeg-devel] [PATCH v5 13/13] avdevice/dshow: select format with extended color info X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 > --- > 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".