From patchwork Thu Jan 5 05:37:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yeoh, Hoong Tee" X-Patchwork-Id: 39875 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp136972pzb; Wed, 4 Jan 2023 21:37:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXuu85MhzMgjHJcuU7V40+jDUZZyYRZwsOFLPbJelzr9Re5kQXMgGbd095+iURvWcT2eW3tQ X-Received: by 2002:a17:907:8c86:b0:7c1:1adc:46fd with SMTP id td6-20020a1709078c8600b007c11adc46fdmr46496638ejc.34.1672897059819; Wed, 04 Jan 2023 21:37:39 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ho18-20020a1709070e9200b0084514612c2asi34449665ejc.609.2023.01.04.21.37.38; Wed, 04 Jan 2023 21:37:39 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b="U/F5IDC8"; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C46CE68BBF1; Thu, 5 Jan 2023 07:37:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7CB9F68B930 for ; Thu, 5 Jan 2023 07:37:27 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672897052; x=1704433052; h=from:to:subject:date:message-id: content-transfer-encoding:mime-version; bh=dEiXYKLvB4EG8RZUFClydU3iIKCEjLin+f8xArNqvGM=; b=U/F5IDC8kdtaxJNTe0f4iocXah+n0O9YSHs+7Ze8H5Lrimh9NgPTCseE 25FKHqFSXZqIyc77prbDbGMJJC1aJjbQqvD9Q6qCJ+DjueimD45BxOmST AD1iADS/TD9s+QFDdaCXGBTEJOUImG4xnFlLTr9I7ip2CZRKUUigc0Ae2 0ePT2vCxFdG3MFN5w46dGoVyX/ECEJsxpoPLh5kDhdGpBlWbiBF7WI3eF gTQtRF4SQ5CtWUDDjma3jLcXumsXpKhcpogFRUIzoXJek95ht4I1XMa63 oEPVEmTHxohs5xmutnmhKe+MM9HKPwGCYAb30By3e5odr04DuxtMeGPKh Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10580"; a="384414283" X-IronPort-AV: E=Sophos;i="5.96,302,1665471600"; d="scan'208";a="384414283" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2023 21:37:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10580"; a="900815643" X-IronPort-AV: E=Sophos;i="5.96,302,1665471600"; d="scan'208";a="900815643" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by fmsmga006.fm.intel.com with ESMTP; 04 Jan 2023 21:37:24 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Wed, 4 Jan 2023 21:37:23 -0800 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Wed, 4 Jan 2023 21:37:23 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.168) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Wed, 4 Jan 2023 21:37:22 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AxmYtyoJPX3WZGnLQQRrVU9CbcyVJxgX4XuUPbDsZlIMsVL7ITvGfaiLA1Uc+NO0X9vIFcVzslZTYpm3YoMJpqq7pPda+drtdGGCxfCSxJX8gE9M6K23RoOdIU13Qsc5oFNScK7W13RpD9MAvC3OZSDlZJuP+hPR/gIWjKYy9mKoawLYDBB6lj6OnAFsUQDK31P1hzY+g4Xt9HPkC5Nt3WYv8J85vreb4nTYoRiocWZU4ONlch6dCxR/Ebaw61bzfqvK6EOXCa1BcCE493b87Yk+FYgBx1ziJtt2RuLbAMP3fdZwyOEDZUtuw4nkCZUtxFaiK2uebhK+e5O4e5UVOQ== 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=YETxkcQsGh7DZFpAyhqoZImd+n30Pz2A1Qyl5sEWgT0=; b=SRYlzG0vKhkGZKgZXIJE4+wUfFUpRELDBr3v/Ir9UQdmFBFaDfLnYPKqmWmWNtKRwGVub7CiheBjZZrGW5NiTR1FkS7DWhFyJeaBifIbN6swQYhlRDCBWvzwLKR9NsZX+9LYgvSXFtjrZSrJz4PTnt0hYwXJFOiT1Xv4gMbFZLoQ1mI20XtfhHLwhd9Ekn7/Zn+o0RC6JVOTPhYBc0LjIkW0QIHcqHj0DHZAxmTgiVydwvxG1BFtriO1fvCQ+lv0eBd2HFTAcHW2BvKgPdrfb//iI82Em2D1Hd1ltCILNsMxdtI7YbQ29a3ESR/cxg3PnC3S55tZBA+3tkVco0CzwQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from CY4PR11MB2038.namprd11.prod.outlook.com (2603:10b6:903:30::14) by MW5PR11MB5930.namprd11.prod.outlook.com (2603:10b6:303:1a1::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Thu, 5 Jan 2023 05:37:20 +0000 Received: from CY4PR11MB2038.namprd11.prod.outlook.com ([fe80::5ae4:fee5:ac92:55bd]) by CY4PR11MB2038.namprd11.prod.outlook.com ([fe80::5ae4:fee5:ac92:55bd%10]) with mapi id 15.20.5944.019; Thu, 5 Jan 2023 05:37:20 +0000 From: "Yeoh, Hoong Tee" To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH] lavf/rtpenc_jpeg: Retrieve sampling factor from SOF0 Thread-Index: Adkfe4ECFkMH/jT0SIWLN0DHfLlQiw== Date: Thu, 5 Jan 2023 05:37:20 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CY4PR11MB2038:EE_|MW5PR11MB5930:EE_ x-ms-office365-filtering-correlation-id: ce1415bc-d0d9-4933-10ae-08daeedee9ff x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: nXPh8h0up5/mvlB/HnOcVXW+RkXtnCLKYw8ApYep3U+nt+XpnPX0p1CaEgDeK1H9xqhnCxs1xds7vKbg6+dMofL9M9ItuXcGnC0mre8Jb8+pcY513uJcw7gTAF3QY9QCxFFTfTu/cR1u9DMGJWB6ptnARrj4hCoNgzgjIPLJYKPrgivMHr3FzOhhVJUluEaY/DJzSnxJnEFIKJyJFEX1AfW7/kvRpz7qAkYMDeovHGj++Clj6izdvFcujOqDFwlpDgGREeuxD0NWHT4+SPRPufUMBvElATZilBwUI09hORiH7VtEgsLFZa6xEKyLwKHoKkTYV2vVnH2Hkcv6yDx8xlEwav13DypXBa9xr/8SRJl6LVSOwq7PZPbRBCrrG7Dqoms1I8iXG4+upYBQhhHQTm86WZC9XdYMMXPDoZCdgcON2yfJZNx6YIikDoITJRFL8V3Th+YY2pnK7t0RzpWkWEPp2Xsy54yrWgOu1p6eIsZu8r4iZMfEZe+ZIG6bENjrgdqaprwba5sIxjBJh+GkNNuWASbK/35ZsXc05gDegZTOQS3QSmXwmkdyBswdbv5qoWu+1/M5CrkO0zq5y2Eoy2i2jKF8qDk/I704x5reNwWO0+AO5pFyYbfOv1zdPwMTBCHphZFk3/G4lnveQHeamlXaqFGxTJFxJcNxI8QwvhFKCfgbuJWHD3jWSdlT4H3lbfGt+lXwnmDdWbvzipUNMA== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CY4PR11MB2038.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(366004)(346002)(39860400002)(136003)(376002)(396003)(451199015)(2906002)(71200400001)(6916009)(316002)(76116006)(66556008)(66946007)(41300700001)(66446008)(66476007)(186003)(26005)(8676002)(5660300002)(83380400001)(9686003)(52536014)(8936002)(7696005)(6506007)(64756008)(38100700002)(33656002)(478600001)(122000001)(86362001)(38070700005)(82960400001)(55016003); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antisp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4cAIYxXpz3SpTDalGetkCKGU/zF2ncMJKGRgcaqisXPloUyuS+jFZPew216nA6zwHR2DzscdXYt+9/s85/6yWg/l9bPvPzaiZ2U0O6rJgDBcrTy9/NNWrNpb9x/higdSGahU3pXonPy2cal2xylqYXP56gxPIHjy3SpA/fu78bjT8O0x/EHzEtfv5TuYrgRrNCIpxGKrgvkYX9KSGfUigEz35lj3SUK4zxHMTNKAM8v5yP8JlQAkE4EpJDUpkqJZnMOCt5LxvTEnrFyHEtsmGMm5JIFZnsLMA7tkSv90iewSp7+2G5h/+6qvDbT6DDvdm5tgXwjnR5ZMH4A5Ie9b4oQOTYBsnBgyCncJOl7numVQwONlx0YJmY76p5TFGdIBswS5OyyjRDtc/yHz6hww69n3faZ0GxTCcRDJoQztJTtntUkUm4f/j9snZ7YqTMl5Opp88h8Zg8n4c9xyVV+GDVK/esRJlAvDfCURW8AzydbADp8ajmxVO2WYexsCrFQyUPJ38pOS1HyE300Kur MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CY4PR11MB2038.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce1415bc-d0d9-4933-10ae-08daeedee9ff X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Jan 2023 05:37:20.2147 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: tkLc5BAIeUf2rZeSoO9rKjK2fAfG1tzoJpE+mSFJDVqehwlB8NEAm+r24X3t1Gh3o/KlxMolF3je2s6E+4QsRq2+ZeUrPK2FqpQtt01PExk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR11MB5930 X-OriginatorOrg: intel.com Subject: [FFmpeg-devel] [PATCH] lavf/rtpenc_jpeg: Retrieve sampling factor from SOF0 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 7jtCWStpy2vx In ff_rtp_send_jpeg, the type is defined based on PIX_FMT and color-range parsed in. There is limitation on current design where need to include support newly introduced PIX_FMT such as AV_PIX_FMT_QSV and there might be more and more in future. Hence, retrive the sampling factor from SOF0 in JPEG compressed header directly. This introduces flexibility to handle the current limitation. Signed-off-by: Yeoh, Hoong Tee --- libavformat/rtpenc_jpeg.c | 41 +++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/libavformat/rtpenc_jpeg.c b/libavformat/rtpenc_jpeg.c index 9111683..53be188 100644 --- a/libavformat/rtpenc_jpeg.c +++ b/libavformat/rtpenc_jpeg.c @@ -30,7 +30,7 @@ void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buf, int size) RTPMuxContext *s = s1->priv_data; const uint8_t *qtables[4] = { NULL }; int nb_qtables = 0; - uint8_t type; + uint8_t type = 2; /* initialized non-0/1 value for RTP/JPEG type check*/ uint8_t w, h; uint8_t *p; int off = 0; /* fragment offset of the current JPEG frame */ @@ -45,20 +45,6 @@ void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buf, int size) w = AV_CEIL_RSHIFT(s1->streams[0]->codecpar->width, 3); h = AV_CEIL_RSHIFT(s1->streams[0]->codecpar->height, 3); - /* get the pixel format type or fail */ - if (s1->streams[0]->codecpar->format == AV_PIX_FMT_YUVJ422P || - (s1->streams[0]->codecpar->color_range == AVCOL_RANGE_JPEG && - s1->streams[0]->codecpar->format == AV_PIX_FMT_YUV422P)) { - type = 0; - } else if (s1->streams[0]->codecpar->format == AV_PIX_FMT_YUVJ420P || - (s1->streams[0]->codecpar->color_range == AVCOL_RANGE_JPEG && - s1->streams[0]->codecpar->format == AV_PIX_FMT_YUV420P)) { - type = 1; - } else { - av_log(s1, AV_LOG_ERROR, "Unsupported pixel format\n"); - return; - } - /* preparse the header for getting some info */ for (i = 0; i < size; i++) { if (buf[i] != 0xff) @@ -90,6 +76,23 @@ void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buf, int size) "Only 1x1 chroma blocks are supported. Aborted!\n"); return; } + + /* + * Find out the sampling factor in SOF0. + * In SOF0, hsample/vsample is inserted in form of (2<<4) | (type ? 2 : 1). + * First 4-bit is hsample while Last 4-bit is vsample. + */ + + /* Luma channel sampling factor in 4:2:2 chroma subsampling are 2x1 */ + if (buf[i + 11] == 33) { + type = 0; + /* Luma channel sampling factor in 4:2:0 chroma subsampling are 2x2 */ + } else if (buf[i + 11] == 34) { + type = 1; + } else { + av_log(s1, AV_LOG_ERROR, "Unsupported pixel format\n"); + return; + } } else if (buf[i + 1] == DHT) { int dht_size = AV_RB16(&buf[i + 2]); default_huffman_tables |= 1 << 4; @@ -163,6 +166,14 @@ void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buf, int size) break; } } + + /* Check validity of RTP/JPEG type */ + if (type != 0 && type != 1) { + av_log(s1, AV_LOG_ERROR, + "Invalid RTP/JPEG type\n"); + return; + } + if (default_huffman_tables && default_huffman_tables != 31) { av_log(s1, AV_LOG_ERROR, "RFC 2435 requires standard Huffman tables for jpeg\n");